Skip to content

Instantly share code, notes, and snippets.

@acoyfellow

acoyfellow/pdf.pdf.js

Last active Mar 24, 2021
Embed
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 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