-
-
Save surfbuds/5692296 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
var http = require('http'); | |
var sys = require('sys'); | |
var exec = require('child_process').exec; | |
var util = require('util'); | |
var fs = require('fs'); | |
http.createServer(function(request, response) { | |
var dummyContent = '<!doctype html><html><head><title>Test</title><meta charset="utf-8"></head><body><p>Hello world!</p></body></html>'; | |
var htmlFileName = "page.html", pdfFileName = "page.pdf"; | |
// Save to HTML file | |
fs.writeFile(htmlFileName, dummyContent, function(err) { | |
if(err) { throw err; } | |
util.log("file saved to site.html"); | |
}); | |
// Convert HTML to PDF with wkhtmltopdf (http://code.google.com/p/wkhtmltopdf/) | |
var child = exec("wkhtmltopdf " + htmlFileName + " " + pdfFileName, function(err, stdout, stderr) { | |
if(err) { throw err; } | |
util.log(stderr); | |
}); | |
response.writeHead(200, {'Content-Type' : 'text/plain'}); | |
response.end('Rendered to ' + htmlFileName + ' and ' + pdfFileName + '\n'); | |
}).listen(8124); | |
console.log('Server running at http://127.0.0.1:8124/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment