Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Urls for Images #2995

Open
BaptisteBrument opened this issue Dec 6, 2024 · 0 comments
Open

Custom Urls for Images #2995

BaptisteBrument opened this issue Dec 6, 2024 · 0 comments

Comments

@BaptisteBrument
Copy link

Describe the bug
The update of @react/pdf/image from 3.0.0 to 3.0.1 has problems with custom URLs

To Reproduce

  1. Use latest version of @react-pdf while having a custom electron protocol in the backend

Expected behavior
The img src is correctly fetched and displayed and the pdf

Desktop (please complete the following information):

  • OS: [Windows]
  • Browser [ chrome (electron)]
  • React-pdf version [4.1.5]

Now @react/pdf/image uses fetch since it is supported natively by node. Before it uses "cross-fetch". I use electron. To handle local files I have to use a custom protocol :

protocol.registerFileProtocol("view-file", (request, callback) => {
		const url = decodeURI(request.url.replace("view-file://", ""));
		try {
			return callback(url);
		} catch (error) {
			console.error(error);
			return callback("404");
		}
	});

"cross-fetch" seems to understand how to handle custom URLs but fetch from node raises an error. I don't know if there is an easy fix (like a parameter to add to make it behave like cross-fetch)

Temporary fix :
Add this to package.json

"resolutions": {
		"@react-pdf/layout/@react-pdf/image": "3.0.0"
	},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant