react-pdf
react-pdf copied to clipboard
Performance rendering in canvas for certain pdf files
Before you start - checklist
- [X] I followed instructions in documentation written for my React-PDF version
- [X] I have checked if this bug is not already reported
- [X] I have checked if an issue is not listed in Known issues
- [X] If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo
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
- Browser (if applicable):
- React-PDF version: 7.3.3
- React version: 18.2.0
- Webpack version (if applicable):
brita-tapfilter-instruction-manual-EN.pdf
This file is a good way of seeing what's going on. Check console after opening it.
I see this error all the time, for what it's worth.
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.
This issue was closed because it has been stalled for 14 days with no activity.