Skip to content

Instantly share code, notes, and snippets.

@acoyfellow
Last active May 3, 2022 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoyfellow/fe9cead2db5090ceca99c17af03a4ae3 to your computer and use it in GitHub Desktop.
Save acoyfellow/fe9cead2db5090ceca99c17af03a4ae3 to your computer and use it in GitHub Desktop.
SvelteKit + pdf-lib
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