title: How to load external assets (image, stylesheets, etc) when using html-pdf in Node.js
body: <p>I'm using <code>html-pdf</code> (<a href="https://www.npmjs.com/package/html-pdf" rel="nofollow noreferrer">NPM page</a>) to generate PDF files in my Node.js app. The way I'm doing it, is first I render the HTML content using Handlebars and then feed the resulting buffer to <code>html-pdf</code>'s <code>create()</code> method. Like this:</p>
  
  <pre><code>var pdfProperties = {
      format: "A4"
  }
  
  fs.readFile('views/project-evaluation-print.hbs', {encoding: 'utf8'}, function(err, data) {
      if (err) return next(err);
      var source = data;
      var html = render(source, pageParameters);
      htmlPdf.create(html, pdfProperties).toStream(function(err, stream) {
          if (err) return next(err);
          stream.pipe(res);
      });
  });
  </code></pre>
  
  <p>I'm using Express, and I serve my assets via routes for each type. So I load them onto a regular HTML like this</p>
  
  <pre><code>&lt;link rel="stylesheet" href="/stylesheets/home-page.css"&gt;
  &lt;img src="/images/logos/app-logo.png"&gt;
  </code></pre>
  
  <p>The problem is, these fail to load when the PDF is generated. I tried doing it like this:</p>
  
  <pre><code>&lt;link rel="stylesheet" href="localhost:8080/stylesheets/home-page.css"&gt;
  &lt;img src="localhost:8080/images/logos/app-logo.png"&gt;
  </code></pre>
  
  <p>I've also tried adding <code>base</code> property to <code>pdfProperties</code></p>
  
  <pre><code>var pdfProperties = {
      format: "A4",
      base: "http://localhost:8080/"
  }
  </code></pre>
  
  <p>But it still doesn't work.</p>