Skip to content

Instantly share code, notes, and snippets.

@rictorres
Created November 19, 2014 18:04
Show Gist options
  • Save rictorres/8dd5abcd9381d2fa13cf to your computer and use it in GitHub Desktop.
Save rictorres/8dd5abcd9381d2fa13cf to your computer and use it in GitHub Desktop.
A simple way of rendering page headers/footers using https://github.com/sgentle/phantomjs-node
var phantom = require('node-phantom');
phantom.create(function (ph) {
ph.createPage(function (page) {
page.open("http://www.google.com", function (status) {
var paperConfig = {
format: 'A4',
orientation: 'portrait',
border: '1cm',
header: {
height: '1cm',
contents: ph.callback(function(pageNum, numPages) {
return '<h1>My Custom Header</h1>';
})
},
footer: {
height: '1cm',
contents: ph.callback(function(pageNum, numPages) {
return '<p>Page ' + pageNum + ' / ' + numPages + '</p>';
})
}
};
page.set('paperSize', paperConfig, function() {
// render to pdf
page.render('path/to/file.pdf', function() {
page.close();
ph.exit();
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment