Overview
The PDF export feature converts your invoices into professional, print-ready PDF documents that can be downloaded, printed, or shared with clients. PDFs are generated entirely in the browser using html2pdf.js, ensuring your invoice data never leaves your device.Generating PDFs
From any invoice detail page (/invoices/[id]), click the Download PDF button to generate and download a PDF file named Invoice_{invoiceNumber}.pdf.
The generation process:
- Retrieves your default company details and bank account information
- Generates HTML markup with inline CSS styling
- Converts HTML to PDF using html2pdf.js
- Automatically downloads the file to your device
PDF generation happens entirely in your browser. No data is sent to external servers, ensuring complete privacy.
PDF structure
The generated PDF includes:Header section
Left side:- “INVOICE” heading in large text
- Invoice number (e.g., Invoice #INV-123456789)
- Invoice date
- Due date
- Company logo (if configured)
- Company name
- Contact email
- Phone number (if configured)
- Full address with city, state, ZIP
- Country
- Tax ID (if configured)
Bill To section
Customer information:- Customer name (bold)
- Email address
- Street address
- City, state, ZIP code
- Country
Line items table
A structured table with columns:- Description: Item or service name
- Quantity: Number of units (right-aligned)
- Rate: Price per unit (right-aligned, formatted with currency)
- Amount: Total for line (right-aligned, formatted with currency)
Amount = Quantity × Rate
Totals section
- Subtotal: Sum of all line item amounts
- Tax: If tax rate > 0, shows “Tax (X%)” with calculated amount
- Total: Final amount due (bold, larger font)
Notes section
Optional section displaying invoice notes if provided. Notes are rendered with line breaks preserved.Payment details section
If you’ve configured a default bank account, the PDF includes:- Account holder name
- Bank name
- Account number
- Sort code (if provided)
- Routing number (if provided)
- IBAN (if provided)
- SWIFT/BIC code (if provided)
- Currency (if provided)
- Payment reference (if provided)
- Additional notes (if provided)
Footer
A simple centered message:Thank you for patronizing us!
HTML generation
The PDF is generated from HTML with embedded CSS. The main function fromapp/lib/pdf.ts:12:
- Calculates totals (subtotal, tax, total)
- Builds HTML string with inline styles
- Conditionally includes company and account information
- Formats all currency values and dates
Styling highlights
- Font: System font stack for universal compatibility
- Colors: Black text on white background for print clarity
- Layout: Flexbox and grid for consistent alignment
- Typography: Clear hierarchy with font sizes from 11px to 28px
- Borders: Subtle gray borders (1px solid #ddd) for sections
- Tables: Striped rows with hover effects (not visible in PDF)
PDF download
The download function fromapp/lib/pdf.ts:344:
PDF options explained
- margin: 10mm on all sides (top, right, bottom, left)
- filename: Dynamic based on invoice number
- image.type: PNG format for embedded images
- image.quality: 0.98 (near-perfect quality)
- html2canvas.scale: 2× for high-resolution rendering
- jsPDF.format: A4 paper size (210mm × 297mm)
- jsPDF.orientation: Portrait mode
Company details integration
To include your company information on PDFs:- Navigate to Settings (if available) or configure via your application
- Add your company details:
- Company name
- Email and phone
- Full address
- Logo (uploaded as image file)
- Tax ID or VAT number
- Mark as default company
- All future PDFs will include this information
Bank account integration
To include payment instructions on PDFs:- Navigate to Settings and add a bank account
- Provide:
- Account holder name
- Bank name
- Account number
- Regional details (sort code, routing number, IBAN, SWIFT/BIC)
- Optional payment reference
- Mark as default account
- All future PDFs will include payment details
Currency formatting
All monetary amounts in the PDF are formatted using theformatCurrency() function from app/lib/invoice.ts:50:
- Proper currency symbols (€, £, $, etc.)
- Correct decimal separators for locale
- Consistent 2 decimal places
- Fallback for unsupported currencies
Date formatting
Dates are formatted usingformatDate() with the “long” format:
Print optimization
The PDF includes print-specific CSS:The generated PDF is optimized for both digital viewing and physical printing. Colors are print-safe and the layout fits standard A4 paper.
Error handling
If PDF generation fails:- An error alert displays: “Failed to download PDF. Please try again.”
- The error is logged to browser console for debugging
- The button returns to its normal state (no longer showing “Generating PDF…”)
- Very large company logos (>5MB)
- Browser compatibility issues
- Insufficient memory on device