-
-
Notifications
You must be signed in to change notification settings - Fork 920
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
customTextRenderer
occasionally inserts HTML content into the <br> tags generated by PDF.js
#1173
Comments
Hi @etripier - Thank you for raising it, I just experienced the same issue. Do you know if there is a workaround to get through it until @wojtekmaj get a chance to take a look ;) |
I don't get it. The length of textContent.items matches the number of rendered children on text layer. If it has |
There is a similar issue reported here #1042 I am experiencing the same issue using this pdf file - https://www.saudiembassy.net/sites/default/files/ContractPublicWorks05.pdf And I am running a simple demo based on this code base but upgrade the react-pdf to 6.1.0 and applied the customTextRenderer like below
|
@wojtekmaj The issue is specifically that some tokens containing text and a line break will render both a |
Thanks guys for all the info - this really helped me out! v6.1.1 released. |
Before you start - checklist
Description
PDF.js inserts a DOM node containing the associated text content if present:
https://github.com/mozilla/pdf.js/blob/c7d6ab2f7123c5a65155c55aa19d9d9abd8c2ff2/src/display/text_layer.js#L368
It then inserts a
<br>
element ifhasEOL
is alsotrue
for the same associated text content:https://github.com/mozilla/pdf.js/blob/c7d6ab2f7123c5a65155c55aa19d9d9abd8c2ff2/src/display/text_layer.js#L371
Because the behavior of
react-pdf
is to iterate through each element of text content and then assume that the DOM node found by index is the only associated DOM node, the count drifts every time an element of text content with length andhasEOL
is hit.I implemented a disgusting hack that looks like
Lmk what you think! Love the ease-of-use of this component.
Steps to reproduce
All the PDF examples I have are confidential but I can try to create one if requested.
str
present andhasEOL: true
.customTextRenderer={({ str }) => str}
Expected behavior
Text selection should match.
Actual behavior
Text selection doesn't match.
Additional information
No response
Environment
The text was updated successfully, but these errors were encountered: