Images not rendering - ctx.EmbedImage
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):
- Create an image element
- 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)

I have the same problem too
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 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.
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.dataand 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.
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.
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.dataand 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
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.
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 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. 🥲
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.dataand 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. 🙏🏽
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.dataand 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.
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
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.dataand 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?