Skip to content

fix: resolve blank page and timeout errors on large PDF exports#174

Closed
ThisIs-Developer wants to merge 4 commits into
mainfrom
fix/large-pdf-export-blank-page
Closed

fix: resolve blank page and timeout errors on large PDF exports#174
ThisIs-Developer wants to merge 4 commits into
mainfrom
fix/large-pdf-export-blank-page

Conversation

@ThisIs-Developer

Copy link
Copy Markdown
Owner

Summary

This PR addresses the critical issue where exporting large markdown documents (12K+ characters) to PDF results in blank/empty pages or causes browser tabs to freeze and timeout.

Root Cause

  1. Canvas Size Limit: Chromium restricts the height of an HTML5 Canvas to exactly 65,535px. Monolithic page rasterization of documents above ~45K characters generated canvases exceeding this size, causing silent allocation failures and empty PDF pages.
  2. PNG Compression Block: The previous serial exporter utilized toDataURL('image/png') for page slicing. PNG's deflate algorithm runs single-threaded on the main JS execution thread, taking ~3.2 seconds per page. For large documents (30+ pages), this blocked the event loop for over 90 seconds, causing browser timeouts or unresponsive script warnings.

Proposed Changes

  1. Hybrid Chunked Capture: Captures the DOM in viewport chunks of up to 8 pages at a time (approx. 9,400px height at standard scale), ensuring canvas bounds remain well below the 65,535px limit.
  2. JPEG Compression: Replaces the heavy PNG compression with native JPEG encoding (0.95 quality). Browser-native JPEG encoding completes in milliseconds, eliminating the single-threaded CPU compression bottleneck and reducing output PDF size by ~70% without visual degradation.
  3. UI Thread Yielding: Yields execution to the browser between chunks/pages using requestAnimationFrame, preventing the main thread from locking up and keeping progress bar animations fluid.
  4. Desktop Sync: Propagated all updates to the NeutralinoJS wrapper desktop asset resource desktop-app/resources/js/script.js via prepare.js.

Performance Results

  • Small Document (5K): PDF export time reduced from 26.3s to 1.8s (14.6x speedup).
  • Medium/Large Document (50K): PDF export time reduced from 84.6s to 11.5s (7.3x speedup) with zero blank pages.
  • Very Large Document (100K): Formerly crashed/failed. Now exports successfully in 32.2s.

Regression Verification

  • Inline images, MathJax LaTeX equations, Mermaid diagrams, and markdown tables break correctly across pages and render with perfect visual fidelity.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
markdown-viwer Ready Ready Preview, Comment Jun 11, 2026 6:35am

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 11, 2026

Copy link
Copy Markdown

Deploying markdown-viewer with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0f8192f
Status: ✅  Deploy successful!
Preview URL: https://73cbf0e9.markdown-viewer.pages.dev
Branch Preview URL: https://fix-large-pdf-export-blank-p.markdown-viewer.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 11, 2026

Copy link
Copy Markdown

Deploying markdownviewer with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0f8192f
Status: ✅  Deploy successful!
Preview URL: https://356fefe1.markdownviewer.pages.dev
Branch Preview URL: https://fix-large-pdf-export-blank-p.markdownviewer.pages.dev

View logs

@ThisIs-Developer ThisIs-Developer force-pushed the fix/large-pdf-export-blank-page branch from 7962822 to 8ca2cfc Compare June 11, 2026 06:24
@ThisIs-Developer ThisIs-Developer deleted the fix/large-pdf-export-blank-page branch June 11, 2026 06:38
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.

1 participant