Prompt
How do I generate invoices as PDFs from my app?
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
To generate invoices as PDFs from your app, the usual flow is:
-
Create invoice data
Build an invoice object with fields like customer name, line items, taxes, totals, invoice number, date, etc. -
Render it into HTML or a PDF template
Most apps generate an invoice as:- HTML/CSS first, then convert to PDF, or
- a server-side PDF document directly using a PDF library.
-
Convert to PDF Use a tool/library depending on your stack.
Common approaches
Option 1: HTML/CSS → PDF
Best if you want invoices to look like normal web pages.
- Node.js: Puppeteer, Playwright
- Python: WeasyPrint, wkhtmltopdf
- PHP: Dompdf, mPDF
- Ruby: Grover, WickedPDF
- Java: OpenHTMLtoPDF
Example flow:
- Generate an HTML invoice template with your data
- Render it in a headless browser
- Save/download the resulting PDF
Option 2: Direct PDF generation
Best if you want precise control and don’t need HTML.
- Node.js: PDFKit
- Python: ReportLab
- Java: iText, Apache PDFBox
- .NET: QuestPDF, iText
This gives more control but usually takes more layout work.
Example: Node.js with Puppeteer
const puppeteer = require('puppeteer');
async function createInvoicePdf(html, outputPath) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(html, { waitUntil: 'networkidle0' });
await page.pdf({
path: outputPath,
format: 'A4',
printBackground: true,
margin: { top: '20mm', right: '15mm', bottom: '20mm', left: '15mm' }
});
await browser.close();
}
Example: Python with ReportLab
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
def create_invoice_pdf(path):
c = canvas.Canvas(path, pagesize=A4)
c.drawString(100, 800, "Invoice #1001")
c.drawString(100, 780, "Customer: Acme Corp")
c.save()
Things to include in an invoice PDF
- Invoice number
- Your business details
- Customer details
- Issue date / due date
- Line items
- Subtotal, tax, discounts, total
- Payment instructions
- Branding/logo
- Terms and conditions
Best practices
- Keep a server-side copy of the generated PDF
- Use a stable template so invoices don’t shift visually
- Embed fonts if you need consistent rendering
- Generate PDFs asynchronously if volume is high
- Store a record of the exact invoice data used
If you want the simplest setup
If your app already uses HTML/CSS, the easiest path is usually:
- design an invoice page in HTML/CSS
- render it with a headless browser like Puppeteer/Playwright
- export to PDF
If you tell me your tech stack, I can give you a ready-to-use example.