Skip to content

Instantly share code, notes, and snippets.



Last active Mar 24, 2021
What would you like to do?
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;
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