fastify-xpdf
PDF generation from HTML/Markdown, form filling, and PDF merging.
fastify-xpdf
PDF generation and manipulation: convert HTML or Markdown to PDF, fill PDF forms, and merge multiple PDFs.
Installation
npm install @xenterprises/fastify-xpdf
Quick Start
await fastify.register(xPDF, {})
// Generate PDF from HTML
fastify.get('/reports/:id/pdf', async (request, reply) => {
const html = await renderReportHtml(request.params.id)
const pdf = await fastify.xpdf.fromHtml(html, {
format: 'A4',
margin: { top: '1cm', bottom: '1cm' },
})
return reply
.header('Content-Type', 'application/pdf')
.header('Content-Disposition', 'attachment; filename="report.pdf"')
.send(pdf)
})
API
// HTML → PDF
const pdf = await fastify.xpdf.fromHtml(html, options)
// Markdown → PDF
const pdf = await fastify.xpdf.fromMarkdown(markdown, options)
// Fill PDF form fields
const filledPdf = await fastify.xpdf.fillForm(templateBuffer, {
firstName: 'John',
lastName: 'Doe',
date: '2024-01-15',
})
// Merge PDFs
const merged = await fastify.xpdf.merge([pdf1Buffer, pdf2Buffer])
AI Context
package: "@xenterprises/fastify-xpdf"
decorates: fastify.xpdf
methods:
fromHtml: HTML string → PDF buffer
fromMarkdown: Markdown string → PDF buffer
fillForm: PDF template buffer + fields object → PDF buffer
merge: PDF buffer[] → combined PDF buffer
use-when: Generating invoices, contracts, reports, or any document download
