Skip to content

Instantly share code, notes, and snippets.

@nessamurmur
Last active December 29, 2015 07:09
Show Gist options
  • Save nessamurmur/7634266 to your computer and use it in GitHub Desktop.
Save nessamurmur/7634266 to your computer and use it in GitHub Desktop.
temp thing.
// Here, under the hood PhantomJS is opening
//localhost:3000/uri/goes/here and rendering it to a pdf.
var pdf = new NodePDF('localhost:3000/uri/goes/here', 'filename.pdf', {width:1440, height:900}); //the options might be optional. Play with it a bit.
// This is a callback for what to do on errors
pdf.on('error', function(msg){
console.log(msg); // you may want to log errors while you're working on it at least.
// What you might really want to do when done is present an error to the user.
});
// This is a callback for what to do when the pdf finishes rendering.
//You want to send your response to the client inside the callback so
//you can ensure the file has been generated before it's requested.
//Otherwise you might get errors that no file has been found.
pdf.on('done', function(pathToFile){
//console.log(pathToFile);
res.render(pathToFile);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment