diegomura / diegomura/react-pdf

Custom Urls for Images

Open
#2,995 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
16.8k
Forks
1.3k
Avg merge
5h 6m
Merged PRs (30d)
52

Description

**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"
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.