Created
April 10, 2015 19:41
-
-
Save danawoodman/ae72b838b7aa56869082 to your computer and use it in GitHub Desktop.
Example of using pdfkit in Node.js
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 fs = require('fs'); | |
var PDFDocument = require('pdfkit'); | |
var pdf = new PDFDocument({ | |
size: 'LEGAL', // See other page sizes here: https://github.com/devongovett/pdfkit/blob/d95b826475dd325fb29ef007a9c1bf7a527e9808/lib/page.coffee#L69 | |
info: { | |
Title: 'Tile of File Here', | |
Author: 'Some Author', | |
} | |
}); | |
// Write stuff into PDF | |
pdf.text('Hello World'); | |
// Stream contents to a file | |
pdf.pipe( | |
fs.createWriteStream('./path/to/file.pdf') | |
) | |
.on('finish', function () { | |
console.log('PDF closed'); | |
}); | |
// Close PDF and write file. | |
pdf.end(); |
The issue of the permissions not working is because the ownerPassword property is missing. I needs to be set for the permissions to work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Didn't notice all the comments till now. Glad it is helping others!
Regarding using with Express, maybe try streaming the response instead of writing to the file?
https://stackoverflow.com/questions/38788721/how-do-i-stream-response-in-express