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

Not valid image extension

Open laclance opened this issue 2 years ago • 8 comments

Trying to render an image but always get Not valid image extension. Image renders fine when using normal img component in react.

Tried using require and buffers.

    const logo = require('assets/printLogo.png');

or

useEffect(() => {
    const toBase64 = (file: Blob): Promise<string> =>
      new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = () => reader.result && resolve(reader.result.toString());
        reader.onerror = error => reject(error);
      });

    async function getFile() {
      const file = new File(['printLogo.png'], 'assets/printLogo.png');
      setLogo(await toBase64(file));
    }

    getFile();
  });

    <Image src={logo} style={{ alignSelf: 'center' }} />

Windows 11 Chrome @react-pdf/renderer": "^3.0.1

laclance avatar Dec 21 '22 13:12 laclance

Trying to render an image but always get Not valid image extension. Image renders fine when using normal img component in react.

Tried using require and buffers.

    const logo = require('assets/printLogo.png');

or

useEffect(() => {
    const toBase64 = (file: Blob): Promise<string> =>
      new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = () => reader.result && resolve(reader.result.toString());
        reader.onerror = error => reject(error);
      });

    async function getFile() {
      const file = new File(['printLogo.png'], 'assets/printLogo.png');
      setLogo(await toBase64(file));
    }

    getFile();
  });
    <Image src={logo} style={{ alignSelf: 'center' }} />

Windows 11 Chrome @react-pdf/renderer": "^3.0.1

I have same issue, but I'm trying to display a cloudinary image with .webp extension. I don't know why, but it was working fine, and now I have this error and cannot display the image.

Bryan03122 avatar Jan 05 '23 16:01 Bryan03122

I have same issue, but I'm trying to display a cloudinary image with .webp extension. I don't know why, but it was working fine, and now I have this error and cannot display the image.

@Bryan03122 when using Cloudinary there's a simple solution:

Use f_png or f_jpg as the transformation - when set, it ignores the extension completely and sends the requested format. AFAIK React-PDF only supports PNG and JPG formats, definitely no webp. Here are some examples: PNG: https://res.cloudinary.com/demo/image/upload/f_png/actor.webp GIF: https://res.cloudinary.com/demo/image/upload/f_gif/actor.webp

bernharduw avatar Jan 10 '23 00:01 bernharduw

I'm also having the same issue, Not a valid image extension,

And I'm using jpeg format which also renders on React image component just fine,

It has an issue while I'm using react-pdf <Image src={--src--} /> component to render images on PDF.

My image has been uploaded to the s3 bucket.

Please suggest me some solution.

laljidp avatar May 17 '23 05:05 laljidp

+1 I am also facing the same issue, any solution so far?

abdullah-aj avatar Nov 03 '23 02:11 abdullah-aj

I'm also having this issue.

<Document>
  <Page size="A4" style={styles.page}>
    <View style={styles.leftColumn}>
      <Image src="./sinch_logo.png" />

index.es.js:903 Not valid image extension

hillriegel avatar Nov 27 '23 14:11 hillriegel

yes I have also tried different paths with the png in the public folder but still get same error.

laclance avatar Nov 30 '23 07:11 laclance

Images shared above are webp which isn't supported. I'll need a valid PNG image where this is happening to replicate

diegomura avatar Feb 03 '24 17:02 diegomura

@diegomura try this screenshot I got today, I tried both png and jpg formats, nothing is working. google

This is the code.

<PDFViewer width={"100%"} height={800}>
      <Document>
        <Page size="A4" style={styles.page}>
          <View style={styles.section}>
            <Image src={"google.png"} style={styles.headerImage}></Image>
          </View>      
        </Page>
      </Document>
</PDFViewer>

The styling is: width: 400px, height: 200px

Edoardo-Croci avatar Feb 19 '24 09:02 Edoardo-Croci

In my case, nothing worked except public dir(express) with correctly converted png image. "@react-pdf/renderer": "^3.3.7"

randbytes avatar Feb 27 '24 11:02 randbytes