Search code examples
javascriptreact-pdf

Why can't I get a image (base64 string) to display


I am having a bit of trouble getting an Image to display. While normally, I would display the image like this:

<img src={"data:image/png;base64," + data.image} id="logoImg" />

... where data.image is a base64 string. However, this gives me no error but I never see the logo on the pdf:

<Image style={styles.logo} src={{ data: "image/png;base64," + data.image}} />

Any help would be appreciated.


Solution

    1. Original Image was a jpeg
    2. I had to put it in a buffer first.
    const buff = new Buffer(data.image, 'base64');
    ...
    <Image style={styles.logo} src={{ data: buff, format: 'jpg' }} />