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

typeError while loading image in pdf.

Open chemseddine201 opened this issue 4 years ago • 8 comments

TypeError: ctx.embedImage is not a function couldn't show an image on the pdf file. <Image style={{ width: 80, backgroundColor: "red" }} fixed cache={false} src={mainLogo+"?rnd="+Math.random()} /> mainLogo: full url of image (string). An error shown on the console but the image fully loaded on network tab.

Uncaught (in promise) TypeError: ctx.embedImage is not a function at drawImage (index.es.js:1221:1) at renderImage (index.es.js:1237:1) at renderNode (index.es.js:2021:1) at renderChild (index.es.js:2000:1) at Array.forEach (<anonymous>) at renderChildren (index.es.js:2003:1) at renderNode (index.es.js:2022:1) at renderChild (index.es.js:2000:1) at Array.forEach (<anonymous>) at renderChildren (index.es.js:2003:1) at renderNode (index.es.js:2022:1) at index.es.js:2106:1 at Array.forEach (<anonymous>) at render (index.es.js:2105:1) at _callee$ (index.js:34:1) at tryCatch (regeneratorRuntime.js:86:1) at Generator._invoke (regeneratorRuntime.js:66:1) at Generator.next (regeneratorRuntime.js:117:1) at asyncGeneratorStep (asyncToGenerator.js:3:1) at _next (asyncToGenerator.js:25:1)

i tried to pass the image a 'blob' and 'base64 string' and same error occurred. any solution ?

chemseddine201 avatar Sep 22 '22 19:09 chemseddine201

same error here on 3.0.0

zeeglenn avatar Oct 07 '22 18:10 zeeglenn

same here. I cannot upgrade to 3.0.0 because of this issue

andresfigueira avatar Oct 14 '22 13:10 andresfigueira

same here

anishpro avatar Oct 18 '22 09:10 anishpro

This is due to using override for "@react-pdf/font": "2.2.1", "@react-pdf/pdfkit": "2.1.0" Removing these will fix this issue. But webpack v4 will give this issue #2015 Fix It by upgrading react scripts to v5

bansaj avatar Oct 20 '22 03:10 bansaj

This is due to using override for "@react-pdf/font": "2.2.1", "@react-pdf/pdfkit": "2.1.0" Removing these will fix this issue. But webpack v4 will give this issue #2015 Fix It by upgrading react scripts to v5

Removed override and upgraded to v5. Also dealt with necessary polyfill webpack config and still got the same "ctx.embedImage is not a function" error

My dependencies:

  "dependencies": {
    "@react-pdf/renderer": "^3.0.0",
    "assert": "^2.0.0",
    "browserify-zlib": "^0.2.0",
    "buffer": "^6.0.3",
    "process": "^0.11.10",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.3.0",
    "react-scripts": "^5.0.1",
    "stream-browserify": "^3.0.0",
    "util": "^0.12.5"
  },
  "devDependencies": {
    "react-app-rewired": "^2.2.1"
  }

EDIT: Using @react-pdf/renderer v2 fixes it but it's obviously not the ideal solution for me. So if anyone knows how to fix it for v3 let us know!

Lure99 avatar Oct 27 '22 11:10 Lure99

Does anyone have a fix for this using webpack 4?

osbash avatar Nov 21 '22 18:11 osbash

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".

fhyem avatar Dec 21 '22 20:12 fhyem

duplicate of https://github.com/diegomura/react-pdf/issues/2089

jeetiss avatar Dec 26 '22 11:12 jeetiss