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

customTextRenderer is not called with various valid PDFs #1530

Closed
4 tasks done
corystevens opened this issue Jun 8, 2023 · 4 comments · Fixed by #1531
Closed
4 tasks done

customTextRenderer is not called with various valid PDFs #1530

corystevens opened this issue Jun 8, 2023 · 4 comments · Fixed by #1531
Labels
bug Something isn't working

Comments

@corystevens
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

After migrating from v6 to v7, the customTextRenderer function is no longer being called for our PDFs. We use this to add document highlighting. The issue seems to be around the TextLayer looking for markedContent classes, which are not present in the rendered DOM for many PDFs I've tested.

PDF test url: https://www.soundczech.cz/temp/lorem-ipsum.pdf

This issue is also present in the test project, so its not related to our code.

Working document with highlighting:
Screenshot 2023-06-08 at 8 47 54 AM

Test document with no highlighting
Screenshot 2023-06-08 at 8 48 10 AM

Looking at the DOM of each document, you can see slight differences in structure.

Working document:
Screenshot 2023-06-08 at 8 49 09 AM

Not working document
Screenshot 2023-06-08 at 8 48 47 AM

Steps to reproduce

Use almost any PDF, have a customTextRenderer, see if that renderer is called. PDFs generated with the "print to PDF" functionality in browsers will have this issue.

Expected behavior

customTextRenderer is called for PDFs

Actual behavior

customTextRenderer is not called for many PDFs

Additional information

No response

Environment

  • Browser (if applicable):
  • Chrome,Firefox
  • React-PDF version:
  • 7.1.1
  • React version:
  • 18
  • Webpack version (if applicable):
@corystevens corystevens added the bug Something isn't working label Jun 8, 2023
@MattL75
Copy link
Contributor

MattL75 commented Jun 9, 2023

Definitely related to the struct tree layer addition. I'm guessing the issue is when you have a pdf that is not tagged, or not tagged properly.

This line const layerChildrenDeep = layer.querySelectorAll('.markedContent > *:not(.markedContent'); would not extract tags that do not have a markedContent class as parent.

@wojtekmaj We could first check that there are items with markedContent class set?

@wojtekmaj
Copy link
Owner

What you say @MattL75 makes total sense to me - let's go for it. :)

@MattL75
Copy link
Contributor

MattL75 commented Jun 9, 2023

I will get on that * at the end of my work day

@wojtekmaj
Copy link
Owner

Fixed in 7.1.2. Thanks @MattL75!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants