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

Image under View render prop Not working

Open Belkacem opened this issue 3 years ago • 4 comments

Describe the bug Image under View render prop we get this error message : Error: TypeError: Cannot read properties of undefined (reading 'width')

To Reproduce Repl link

Expected behavior Should display an Image

Desktop (please complete the following information):

  • OS: MacOS
  • Browser chrome,
  • React-pdf version 2.3.0

Belkacem avatar Jul 13 '22 11:07 Belkacem

I did const Quixote = () => ( <Document> <Page style={styles.body}> <View> <Image style={styles.image} src="/images/quijote1.jpg" /> </View> </Page> </Document> );

and it worked fine. Not sure why you do <View render={() => <Image style={styles.image} src="/images/quijote1.jpg" /> } fixed />

mirankorkmaz avatar Jul 28 '22 21:07 mirankorkmaz

I need to render an image only on some pages

Belkacem avatar Jul 29 '22 06:07 Belkacem

If I've understood this dependency correctly, you need to do it manually. const Quixote = () => ( <Document> <Page style={styles.body}> <View> <Image style={styles.image} src="/images/quijote1.jpg" /> </View> </Page> <Page style={styles.body}> <View> <Image style={styles.image} src="/images/quijote1.jpg" /> </View> </Page> <Page style={styles.body}> <Text>Hello World</Text> </Page> </Document> );

mirankorkmaz avatar Jul 29 '22 07:07 mirankorkmaz

Thanks for the effort, but your suggestion doesn't resolve the problem. even if my use case has another solution, there's clearly a bug here and FYI it was working on older versions of react-pdf. Cheers :-)

Belkacem avatar Jul 29 '22 08:07 Belkacem