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

Can't find Page object in customTextRenderer layer prop on v6.0.3 (works on v5.7.2) #1190

Closed
4 tasks done
sherryzhang001 opened this issue Nov 23, 2022 · 7 comments
Closed
4 tasks done
Labels
enhancement New feature or request

Comments

@sherryzhang001
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

On v6.0.3, customTextRenderer no longer provide Page object in layer prop. Is there any reason for removing it? Currently we are using _pageIndex to do a cross div search, without it we couldn't tell which page the text is on.
Screen Shot 2022-11-23 at 15 23 13
Screen Shot 2022-11-23 at 14 13 11
Screen Shot 2022-11-23 at 11 41 01

Steps to reproduce

console log the layer prop of customTextRenderer function.

Expected behavior

get same object as in v5.7.2

Actual behavior

Page object no longer in it

Additional information

No response

Environment

  • Browser (if applicable): Chrome 107
  • React-PDF version: 6.0.3
  • React version: 17.0.2
  • Webpack version (if applicable):
@sherryzhang001 sherryzhang001 added the bug Something isn't working label Nov 23, 2022
@wojtekmaj
Copy link
Owner

This was never documented/intended.

@wojtekmaj wojtekmaj added enhancement New feature or request and removed bug Something isn't working labels Nov 23, 2022
@paescuj
Copy link
Contributor

paescuj commented Nov 23, 2022

This was never documented/intended.

Additionally, this has been announced as a breaking change in v6.0.0 (#944).

If you still need to access the current page you can easily control and track it via pageIndex.

@sherryzhang001
Copy link
Author

This was never documented/intended.

Additionally, this has been announced as a breaking change in v6.0.0 (#944).

If you still need to access the current page you can easily control and track it via pageIndex.

Could you explain more about it? How can I get pageIndex in customTextRenderer?

@wojtekmaj
Copy link
Owner

wojtekmaj commented Nov 23, 2022

Yeah, I actually don't see an easy way to do this unless you inline customTextRenderer and you have direct access to pageIndex you use to render Page components :D I'd be able to work around it, but no reason to force everyone else to suffer from it.

@paescuj
Copy link
Contributor

paescuj commented Nov 23, 2022

Pretty simple:

const [pageIndex, setPageIndex] = useState(0);

<Page
  pageIndex={pageIndex}
  customTextRenderer={
    (textItem) => myCustomTextRenderer(textItem, pageIndex)
  }
 />

But of course, it is more convenient if it is available out of the box 😄 So, thanks @wojtekmaj for 34fbf09!

@sherryzhang001
Copy link
Author

Yeah, I actually don't see an easy way to do this unless you inline customTextRenderer and you have direct access to pageIndex you use to render Page components :D I'd be able to work around it, but no reason to force everyone else to suffer from it.

Thank you so much for the update!! May I ask when will this change be released?

@EricLiu0614
Copy link

@wojtekmaj - Thank you for making the change! I also wondering when the new release will be published :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants