Last active
May 3, 2022 07:33
-
-
Save acoyfellow/fe9cead2db5090ceca99c17af03a4ae3 to your computer and use it in GitHub Desktop.
SvelteKit + pdf-lib
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
import pkg from 'pdf-lib/cjs/index.js'; | |
const { PDFDocument } = pkg; | |
export const get = async (req, context) => { | |
const pdfDoc = await PDFDocument.create(); | |
const page = pdfDoc.addPage(); | |
page.drawText('You can create PDFs!'); | |
const pdfBytes = await pdfDoc.save(); | |
return { | |
body: Buffer.from(pdfBytes, 'binary'), | |
status: 200, | |
headers: { | |
'Content-Type': 'application/pdf', | |
'Content-Disposition': `filename=hello-world.pdf`, | |
'Content-Length': pdfBytes.length | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment