Menu

pdf.js render() resolves fine on a huge page, but the canvas reads back transparent
📰

pdf.js render() resolves fine on a huge page, but the canvas reads back transparent

DEV Community: javascript·hao jia·16 days ago
#55oNUnbd
#devtojavascript#devto#dev#canvas#thrown
Reading 0:00
15s threshold

A failed render ought to look like a failure: a rejected promise, an exception, something in the console. With pdf.js on an oversized page it does not. The promise resolves, the code after await runs, and the canvas you hand to the next step is empty. All numbers below come from one machine (Apple M4, desktop Chromium 149.0.7827.55, pdfjs-dist 4.4.168), single runs, on a blank vector page I generated myself. Other browsers and phones have different limits, and I did not test them.

What the render call reported

The page was 14400 × 14400 pt. I rendered it at four scales and read pixels back from the canvas afterwards. At scale 0.5 (7200 × 7200) and scale 1 (14400 × 14400) the top-middle pixel was opaque white, as expected. At scale 1.1 the canvas was 15840 × 15840 and still fine, with the page's border colour showing up at the edge.

At scale 1.3333333 the canvas would be 19199 × 19199, an area of 368,601,601 pixels.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.