Skip to content

Instantly share code, notes, and snippets.

@kiichi
Created June 30, 2015 13:30
Show Gist options
  • Select an option

  • Save kiichi/0bc04e9fdb4818be2c59 to your computer and use it in GitHub Desktop.

Select an option

Save kiichi/0bc04e9fdb4818be2c59 to your computer and use it in GitHub Desktop.
PDFKit Node Http Server
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);
});
Copy link
Copy Markdown

ghost commented Jan 15, 2017

Well done! I was looking for such an example! :D

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