Last active
November 4, 2016 12:51
-
-
Save vnglst/b15187c065dd4f065c0949b6177c6cab 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
const express = require('express') | |
const router = express.Router() | |
const PDFDocument = require('pdfkit') | |
router.post('/', (req, res) => { | |
const doc = new PDFDocument() | |
let filename = req.body.filename | |
// Stripping special characters | |
filename = encodeURIComponent(filename) + '.pdf' | |
// Setting response to 'attachment' (download). | |
// If you use 'inline' here it will automatically open the PDF | |
res.setHeader('Content-disposition', 'attachment; filename="' + filename + '"') | |
res.setHeader('Content-type', 'application/pdf') | |
const content = req.body.content | |
doc.y = 300 | |
doc.text(content, 50, 50) | |
doc.pipe(res) | |
doc.end() | |
}) | |
module.exports = router |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment