Created
May 18, 2014 13:31
-
-
Save cryptojuice/151ce99f86d4f45ddf5b to your computer and use it in GitHub Desktop.
Phantomjs render pdf to /dev/stdout
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
spawn = require('child_process').spawn | |
express = require('express') | |
app = express() | |
generatePDF = (callback) -> | |
child = spawn('phantomjs', [__dirname+'/render.coffee']) | |
child.stdout.on 'data', (data) -> | |
callback(null, data) | |
child.stdout.on 'error', (err) -> | |
callback(err) | |
app.get '/', (req, res) -> | |
res.set 'Content-type', 'application/pdf' | |
res.set 'Content-disposition', 'inline; filename="agreement.pdf"' | |
generatePDF (err, data) -> | |
throw err if err? | |
res.send data |
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
page = require | |
page.content = '<html><body><h1>Hello, World</h1></body></html>' | |
page.render '/dev/stdout', format: 'pdf' | |
phantom.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment