Created
April 27, 2017 00:18
-
-
Save omartrigui/8cb6b5d6ccd94e4dca03613bc070320c to your computer and use it in GitHub Desktop.
Rendering HTML pages to PDF using PhantomJS (custom format, footer, margin ...)
This file contains hidden or 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
var page = require('webpage').create(); | |
var cookie = { | |
// your cookie here | |
}; | |
page.paperSize = { | |
format: 'A4', | |
footer: { | |
height: "2cm", | |
contents: phantom.callback(function(pageNum, numPages) { | |
return "<h4>Footer <span style='float:right'>" + pageNum + " / " + numPages + "</span></h4>"; | |
}) | |
}, | |
margin: { | |
left: '1cm', | |
right: '1cm' | |
} | |
}; | |
page.addCookie(cookie); | |
page.open('url here ...', function() { | |
window.setTimeout(function() { | |
page.render('rendered_page.pdf'); | |
phantom.exit(); | |
}, 10000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment