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
PDF text not displayed correctly when embedded in popup window using React Portal #616
Comments
I have realized that if I set pdfjs option Note that all the PDFs are rendered correctly if the Based on some potentially related discussions: mozilla/pdf.js#11955 (very helpful) and the definition of the
I suspect my issue is caused by a font face loading problem in the popup window. But I don't know this topic well enough to further troubleshoot. |
Yeah, since fonts are added to the document that loads React-PDF, you would need to load React-PDF in popup. Otherwise the popup doesn't have access to the fonts, and consequently displays gibberish. Not sure how to achieve this using this specific library, so I'm going to leave this open for the community to help. |
Notice that we have the exact same issue in electron |
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days. |
Ok, I've made a promising discovery: There is Line 277 in 99a0fcf
It looks like DocumentInitParameters has something called So if you could pass a reference to popup window using this option like so: // Note: make sure to memoize this object
const options = {
ownerDocument: popupRef.document,
};
// Render this somewhere in popupRef document
<Document options={options} file={…} /> then fonts should render properly. |
Pardon my French but fuck yes! Here's a working example: https://codesandbox.io/s/react-pdf-popup-vco8p Note: This should work with React-PDF 5.3.0 and later. React-PDF 4.1.0 used by OP does not support this option. |
Thank you so much for your persistent effort!! It is great to know this problem has been addressed and learned a lot from your solution! |
Before you start - checklist
Description
My use cases involves using React Portal to display PDF in a new popup window, more or less following this blog post: https://medium.com/hackernoon/using-a-react-16-portal-to-do-something-cool-2a2d627b0202
However, text will not display correctly in the popup window, when the same PDF is displayed properly in the main browser window. This seems to happen for all my PDF files.
Steps to reproduce
Please see the sandbox https://codesandbox.io/s/objective-noether-7nplp?file=/src/App.js
Note that you need to choose "Open in New Window" to avoid the iframe security error.
Environment
The text was updated successfully, but these errors were encountered: