Search code examples
node.jspdfnpmnode-html-pdf

Node JS Html-pdf : create different header footer for first and last page


I am new in node js, and I want to use different header and footer for first and last pages in node js,

I am using html-pdf module which is not working when I use the same code as they have provided.

please have a look into the code

var fs = require('fs');
var pdf = require('html-pdf');
var html = fs.readFileSync('test.html', 'utf8');
var options = { format: 'Letter' };

pdf.create(html, options).toFile('businesscard.pdf', function(err, res) {
  if (err) return console.log(err);
  console.log(res); // { filename: '/app/businesscard.pdf' }
});

Reference Link: https://www.npmjs.com/package/html-pdf

When I am using below code It will not work on the last page only It also print for middles pages.

<div id="pageHeader-last">Header on last page</div>
...
<div id="pageFooter-last">Footer on last page</div>

Solution

  • you can use html-pdf for node https://www.npmjs.com/package/html-pdf It is working in the html-pdf version 2.1.0 you can install it via npm install [email protected] There is some issue with latest version (2.2.0)