Large PDFs are slow to generate, transfer, and open. Optimizing PDFs improves user experience and reduces infrastructure costs.
Image Optimization
Images are the biggest contributor to PDF size. Compress images before embedding: use JPEG for photos (quality 80-85), PNG for graphics with transparency, SVG for vector graphics (smallest). Resize images to display dimensions—don't embed a 4000px image to display at 500px. Image compression can reduce PDF size by 70-90%.
Font Embedding
Custom fonts increase PDF size. Use web-safe fonts (Arial, Times, Helvetica) when possible—they're not embedded. If custom fonts are required, subset fonts (include only used characters) rather than full fonts. Subsetting can reduce font size from 200KB to 20KB. PDF generators often subset automatically.
Caching and Reuse
If generating the same PDF repeatedly (e.g., invoices from templates), cache the rendered PDF for 24 hours. Use content-based cache keys (hash of HTML + parameters). Serve cached PDFs instantly (0ms) rather than regenerating (2-3 seconds). For invoices with unique data, cache the template structure and inject data at render time.