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

Svg images and external image url are not working in react-pdf

Open AlimKhan76 opened this issue 8 months ago • 3 comments

Describe the bug External image url of svg and png are not working wiht react-pdf Image tag

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

You can make use of react-pdf REPL to share the snippet

Expected behavior

  • The image should be loaded and rendered in the PDF

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. MacOS, Windows]
  • Browser [e.g. chrome, safari]
  • React-pdf version [e.g. v1.1.0]

AlimKhan76 avatar Apr 25 '25 09:04 AlimKhan76

same issue

islam-kamel avatar May 05 '25 07:05 islam-kamel

@islam-kamel can you try this,

import axios from 'axios';

export const getImageBuffer= async (url: string) => {

	const imageResponse = await axios.get(url, {
		responseType: 'arraybuffer',
	});
	console.log('Image fetched successfully');

	const imageBuffer = Buffer.from(imageResponse.data, 'binary');
	console.log('Image buffer created', imageBuffer.length);
	return imageBuffer;
};

The above might work for external non svg images

AlimKhan76 avatar May 05 '25 09:05 AlimKhan76

@islam-kamel can you try this,

import axios from 'axios';

export const getImageBuffer= async (url: string) => {

	const imageResponse = await axios.get(url, {
		responseType: 'arraybuffer',
	});
	console.log('Image fetched successfully');

	const imageBuffer = Buffer.from(imageResponse.data, 'binary');
	console.log('Image buffer created', imageBuffer.length);
	return imageBuffer;
};

The above might work for external non svg images

This worked. Images should be passed as Base64.

m-muiznieks avatar May 31 '25 19:05 m-muiznieks