react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Performance rendering in canvas for certain pdf files

Open GunterJameda opened this issue 1 year ago • 2 comments

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):

GunterJameda avatar Oct 10 '23 21:10 GunterJameda

brita-tapfilter-instruction-manual-EN.pdf

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

GunterJameda avatar Oct 13 '23 14:10 GunterJameda

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

Heilemann avatar Dec 25 '23 22:12 Heilemann

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] avatar Mar 25 '24 00:03 github-actions[bot]

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

github-actions[bot] avatar Apr 15 '24 00:04 github-actions[bot]