wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.
https://projects.wojtekmaj.pl/react-pdf
MIT License
9.24k stars 877 forks source link

Performance rendering in canvas for certain pdf files #1634

Closed GunterJameda closed 4 months ago

GunterJameda commented 11 months ago

Before you start - checklist

Description

I'm not exactly sure this qualifies as a bug or not, but this is something I faced when parsing a pdf page to png, which uses the exact same method as to render the page in a canvas and after we export it to base64.

The warning message I'm getting is this:

Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true. See: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently.

I fixed it by adding a prop in the canvas render context that indicated that it will be read often and the problem went away.

const context = canvas.getContext("2d", {
  willReadFrequently: true,
});

Is it possible to find a way to pass this as a prop or something similar?

I can provide a file as a way to get the test done, but I can't assure the message will popup, since it's an on and off situation.

Steps to reproduce

We need a file that would throw this error and then we should render it and check console.

Expected behavior

Not having the warning message

Actual behavior

We have the warning message

Additional information

No response

Environment

GunterJameda commented 11 months ago

brita-tapfilter-instruction-manual-EN.pdf

This file is a good way of seeing what's going on. Check console after opening it.

Heilemann commented 8 months ago

I see this error all the time, for what it's worth.

github-actions[bot] commented 5 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

github-actions[bot] commented 4 months ago

This issue was closed because it has been stalled for 14 days with no activity.