Skip to content

Instantly share code, notes, and snippets.

@bojoer
Created February 8, 2014 14:47
Show Gist options
  • Save bojoer/8884812 to your computer and use it in GitHub Desktop.
Save bojoer/8884812 to your computer and use it in GitHub Desktop.
// html2pdf.js
var page = new WebPage();
var system = require("system");
// change the paper size to letter, add some borders
// add a footer callback showing page numbers
page.paperSize = {
format: "A4",
orientation: "portrait",
footer: {
height: "0.9cm",
contents: phantom.callback(function (pageNum, numPages) {
return "<div style='text-align:center;'><small>" + pageNum +
" / " + numPages + "</small></div>";
})
}
};
page.zoomFactor = 1;
// assume the file is local, so we don't handle status errors
page.open(system.args[1], function (status) {
page.render(system.args[2]);
phantom.exit();
});
// phantomjs html2pdf.js invoice.html invoice.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment