Skip to content

Prevent blank PDF exports for large Markdown documents by bounding html2canvas render scale#65

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/fix-empty-pdf-export
Draft

Prevent blank PDF exports for large Markdown documents by bounding html2canvas render scale#65
Copilot wants to merge 7 commits intomainfrom
copilot/fix-empty-pdf-export

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Large Markdown documents could produce empty PDFs because the export pipeline attempted canvas captures beyond browser-safe limits; small files continued to work because they stayed below those thresholds.

  • Root cause addressed: oversized canvas capture in PDF export

    • Added explicit safety bounds for PDF rasterization:
      • MAX_PDF_CANVAS_DIMENSION (per-side cap)
      • MAX_PDF_CANVAS_AREA (total pixel cap)
      • MIN_READABLE_PDF_SCALE (lower bound for legibility)
    • Computes a safeScale from document dimensions + bounds before calling html2canvas, preventing blank output from failed/invalid canvas allocation.
  • Export capture now uses actual rendered element dimensions

    • Replaced fixed capture sizing assumptions with measured values from the offscreen export container (actualElementWidth, actualElementHeight).
    • Passes these dimensions into html2canvas (windowWidth, windowHeight) to keep pagination math and capture behavior aligned for long documents.
  • Maintainability improvements in PDF export path

    • Centralized scale/limit constants near existing PDF page config.
    • Added targeted inline documentation for scaling fallback behavior and browser-limit rationale.
const dimensionLimitedScale = Math.min(
  MAX_PDF_CANVAS_DIMENSION / actualElementWidth,
  MAX_PDF_CANVAS_DIMENSION / actualElementHeight
);
const areaLimitedScale = Math.sqrt(MAX_PDF_CANVAS_AREA / (actualElementWidth * actualElementHeight));
const safeScale = Math.max(
  MIN_READABLE_PDF_SCALE,
  Math.min(desiredScale, dimensionLimitedScale, areaLimitedScale)
);

Copilot AI and others added 7 commits April 3, 2026 09:04
Agent-Logs-Url: https://github.com/ThisIs-Developer/Markdown-Viewer/sessions/d80d4d3a-e671-48a7-8411-d69ce79349a8

Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ThisIs-Developer/Markdown-Viewer/sessions/d80d4d3a-e671-48a7-8411-d69ce79349a8

Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ThisIs-Developer/Markdown-Viewer/sessions/d80d4d3a-e671-48a7-8411-d69ce79349a8

Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ThisIs-Developer/Markdown-Viewer/sessions/d80d4d3a-e671-48a7-8411-d69ce79349a8

Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ThisIs-Developer/Markdown-Viewer/sessions/d80d4d3a-e671-48a7-8411-d69ce79349a8

Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ThisIs-Developer/Markdown-Viewer/sessions/d80d4d3a-e671-48a7-8411-d69ce79349a8

Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
…ml2canvas render scale

Agent-Logs-Url: https://github.com/ThisIs-Developer/Markdown-Viewer/sessions/d80d4d3a-e671-48a7-8411-d69ce79349a8

Co-authored-by: ThisIs-Developer <109382325+ThisIs-Developer@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
markdown-viwer Ready Ready Preview, Comment Apr 3, 2026 9:11am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants