Last active
August 29, 2015 13:56
-
-
Save mickaelandrieu/9009983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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