Skip to content

Instantly share code, notes, and snippets.

@mickaelandrieu
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mickaelandrieu/9009983 to your computer and use it in GitHub Desktop.
Save mickaelandrieu/9009983 to your computer and use it in GitHub Desktop.
/**
* @author Thomas Bley
* @licence GNU-FDL
* Source: http://we-love-php.blogspot.fr/2012/12/create-pdf-invoices-with-html5-and-phantomjs.html
*/
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: "Letter",
orientation: "portrait",
margin: {left:"2.5cm", right:"2.5cm", top:"1cm", bottom:"1cm"},
footer: {
height: "0.9cm",
contents: phantom.callback(function(pageNum, numPages) {
return "<div style='text-align:center;'><small>" + pageNum +
" / " + numPages + "</small></div>";
})
}
};
page.zoomFactor = 1.5;
// assume the file is local, so we don't handle status errors
page.open(system.args[1], function (status) {
// export to target (can be PNG, JPG or PDF!)
page.render(system.args[2]);
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment