fix: reduce PDF export file size (#240)#259
Merged
shaynesidman merged 1 commit intomainfrom Apr 22, 2026
Merged
Conversation
- Enable jsPDF document-level compression ({ compress: true }) in all
PDF constructors (export-to-pdf.ts, heatmap-export.ts)
- Switch canvas captures from lossless PNG to JPEG at 0.75 quality
(export-to-pdf.ts, useCart.tsx)
- Reduce html2canvas scale from 2x to 1.5x — still sharp at PDF
resolution but produces ~44% fewer pixels
- Add FAST compression to all addImage calls for further deflate savings
- Use image aliases for header logos so jsPDF reuses the same data
across pages instead of re-embedding the ~78KB PNG each time
- Lower heatmap JPEG quality from 1.0 to 0.75 (heatmap-export.ts)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
#240 — PDF file size is too big
Who worked on this sprint/bug?
Cursor agent
Who did what on this sprint/bug?
All changes implemented together — focused on compression and image optimization across the entire PDF export pipeline.
Features Implemented
Five complementary optimizations that together should dramatically reduce exported PDF file sizes:
new jsPDF({ compress: true })enables deflate stream compression on all PDF content (export-to-pdf.ts, heatmap-export.ts)canvas.toDataURL()(default PNG/lossless) →canvas.toDataURL("image/jpeg", 0.75)— JPEG at 75% quality is much smaller for chart images with solid backgroundsscale: 2→scale: 1.5— still sharp at PDF print resolution (~108 DPI) but produces ~44% fewer pixels per capture"FAST"compression parameter to everypdf.addImage()call for additional deflate savings"mhd-logo","mhs-logo") to header logoaddImagecalls so jsPDF reuses the same image data across pages instead of re-embedding the ~78KB PNG on every page of multi-page PDFsNew files created
None
Existing files modified
src/lib/export-to-pdf.ts— compress flag, JPEG output, reduced scale, FAST compression on addImagesrc/lib/heatmap-export.ts— compress flag, reduced JPEG quality, FAST compression on addImagesrc/lib/pdf-layout.ts— FAST compression + alias deduplication for header logossrc/hooks/useCart.tsx— reduced html2canvas scale, JPEG output for cart chart renderingAcceptance Criteria
Testing: how did you test?
Features Not Implemented/Incomplete
None — this is a pure optimization change with no feature additions.
Bugs Discovered
Pre-existing TS2307 warnings for PNG image imports in
pdf-layout.ts(missing type declarations for.pngmodules). Not introduced by this PR.Screenshots:
N/A — output PDFs look the same, just smaller.
Tag Dan and Shayne
@danglorioso @shaynesidman