Skip to content

Instantly share code, notes, and snippets.

@philfreo
Created June 24, 2013 23:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save philfreo/5854629 to your computer and use it in GitHub Desktop.
Save philfreo/5854629 to your computer and use it in GitHub Desktop.
PhantomJS: generate PDF to stdout from HTML in stdin. Example: echo "<b>test</b>" | phantomjs makepdf.js > test.pdf && open test.pdf
var page = require('webpage').create(),
fs = require('fs');
page.viewportSize = { width: 600, height: 600 };
page.paperSize = { format: 'Letter', orientation: 'portrait', margin: '1cm' };
page.content = fs.read('/dev/stdin');
window.setTimeout(function() {
page.render('/dev/stdout', { format: 'pdf' });
phantom.exit();
}, 1);
Copy link

ghost commented Jul 23, 2015

Broken on Linux due to: ariya/phantomjs#12780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment