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

Images not rendering - ctx.EmbedImage

Open osbash opened this issue 4 years ago • 13 comments

Describe the bug When rendering an image, console throw an error ctx.EmbedImage is not a function This bug exists in v2 and v3 of react-pdf

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

  1. Create an image element
  2. Pass a base64 string or image URL string

Expected behavior Expected the image to render in place

Desktop (please complete the following information):

  • OS: Mac OS 13 Ventura
  • Browser Chrome
  • React-pdf version v 2.2.0 and v3.0.1

I noticed embedImage is not included in the Context.ts types (v 2.1.0), so I commented out lines 1220 - 1222 of @react-pdf/render/lib/index.es.js and the images started to render as expected. (screenshot)

Screenshot 2022-11-21 at 6 43 13 PM

osbash avatar Nov 22 '22 00:11 osbash

I have the same problem too

Krukovich avatar Dec 01 '22 12:12 Krukovich

I am experiencing the same issue, instead of commenting out the code I've just did that:

image = imageCache.get(cacheKey) || ctx.embedImage ? ctx.embedImage(node.image.data) : node.image.data

and It worked as expected. @diegomura are we using it wrong and there is a better way, or should we make the change and maybe open a PR for the fix?

ramtaylor avatar Dec 14 '22 10:12 ramtaylor

I am facing this problem too. "@react-pdf/renderer": "^3.0.0". Image is rendering in another component just fine but throws error in one component. "ctx.embedImage is not a function". Also I could not find the file as mentioned above because i use a newer version.

fhyem avatar Dec 21 '22 19:12 fhyem

I am experiencing the same issue, instead of commenting out the code I've just did that:

image = imageCache.get(cacheKey) || ctx.embedImage ? ctx.embedImage(node.image.data) : node.image.data

and It worked as expected. @diegomura are we using it wrong and there is a better way, or should we make the change and maybe open a PR for the fix?

I found when there are more than one Image tags the error show up. The code is exactly what you have described.

fhyem avatar Dec 22 '22 18:12 fhyem

I was able to get this resolved using v2.1.2.

Update package.json to use

@react-pdf/renderer": "2.1.2"

In the resolutions section of package.json add:

"@react-pdf/font": "2.2.0",
"@react-pdf/pdfkit": "2.4.0",
"react-pdf/pdfjs-dist": "2.0.550"

This seems to have done the trick, without having to alter the package code.

osbash avatar Dec 22 '22 18:12 osbash

I am experiencing the same issue, instead of commenting out the code I've just did that:

image = imageCache.get(cacheKey) || ctx.embedImage ? ctx.embedImage(node.image.data) : node.image.data

and It worked as expected. @diegomura are we using it wrong and there is a better way, or should we make the change and maybe open a PR for the fix?

Thanks! works for me

vargased94 avatar Dec 23 '22 21:12 vargased94

I resolved the issue with a simple solution. just change the image source to a different name when using more than one Image. Make more than one copies of the image and import them with different names.

fhyem avatar Dec 25 '22 17:12 fhyem

I can't reproduce the problem it works in the repl

Could you provide more steps to reproduce? please create repo or repl with the bug

jeetiss avatar Dec 26 '22 11:12 jeetiss

@jeetiss your so quick to close all isuess related to the error above. but the error still exist. yeah it works in repl. but somthings seems to be. wrong. 🥲

tdammy92 avatar Jun 27 '23 23:06 tdammy92

I am experiencing the same issue, instead of commenting out the code I've just did that:

image = imageCache.get(cacheKey) || ctx.embedImage ? ctx.embedImage(node.image.data) : node.image.data

and It worked as expected. @diegomura are we using it wrong and there is a better way, or should we make the change and maybe open a PR for the fix?

Thank you this, fixed my issue. 🙏🏽

tdammy92 avatar Jun 28 '23 08:06 tdammy92

This also happens to me, running the project in any system I tried (even in some docker images), with Node 16.20.

The fix from this comment make it works:

I am experiencing the same issue, instead of commenting out the code I've just did that:

image = imageCache.get(cacheKey) || ctx.embedImage ? ctx.embedImage(node.image.data) : node.image.data

and It worked as expected. @diegomura are we using it wrong and there is a better way, or should we make the change and maybe open a PR for the fix?

Any idea if this will be patched sometime in the future? I'm currently overriding it with https://github.com/ds300/patch-package but it's obviously not the best option to handle this.

Ccastillo06 avatar Jun 30 '23 10:06 Ccastillo06

I was able to get this resolved using v2.1.2.

Update package.json to use

@react-pdf/renderer": "2.1.2"

In the resolutions section of package.json add:

"@react-pdf/font": "2.2.0",
"@react-pdf/pdfkit": "2.4.0",
"react-pdf/pdfjs-dist": "2.0.550"

This seems to have done the trick, without having to alter the package code.

Thanksss finally I can fix this issue

rafatillmann avatar Aug 18 '23 17:08 rafatillmann

I have the same issue, and I want to know if the below solution is developed in any version.

I am experiencing the same issue, instead of commenting out the code I've just did that:

image = imageCache.get(cacheKey) || ctx.embedImage ? ctx.embedImage(node.image.data) : node.image.data

and It worked as expected. @diegomura are we using it wrong and there is a better way, or should we make the change and maybe open a PR for the fix?

victor-felix avatar Dec 04 '23 02:12 victor-felix