Created
June 30, 2015 13:30
-
-
Save kiichi/0bc04e9fdb4818be2c59 to your computer and use it in GitHub Desktop.
PDFKit Node Http Server
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 http = require('http'); | |
| var fs = require('fs'); | |
| var PDFDocument = require('pdfkit'); | |
| function handleRequest(req, res){ | |
| var doc = new PDFDocument(); | |
| doc.pipe(res); | |
| doc.fontSize(25).text('pdf server - requested URL:' + req.url, 100, 80); | |
| doc.save().moveTo(100, 150).lineTo(100, 250).lineTo(200, 250).fill("#FF3300"); | |
| doc.circle(280, 200, 50).fill("#6600FF").restore(); | |
| doc.end(); | |
| } | |
| var port = 80; | |
| var server = http.createServer(handleRequest); | |
| server.listen(port, function(){ | |
| console.log("Server listening on: http://localhost:%s", port); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well done! I was looking for such an example! :D