Skip to content

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

Closed
@sherryzhang001

Description

@sherryzhang001

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):

Activity

wojtekmaj

wojtekmaj commented on Nov 23, 2022

@wojtekmaj
Owner

This was never documented/intended.

added
enhancementNew feature or request
and removed
bugSomething isn't working
on Nov 23, 2022
paescuj

paescuj commented on Nov 23, 2022

@paescuj
Contributor

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

sherryzhang001 commented on Nov 23, 2022

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

wojtekmaj commented on Nov 23, 2022

@wojtekmaj
Owner

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

paescuj commented on Nov 23, 2022

@paescuj
Contributor

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

sherryzhang001 commented on Nov 24, 2022

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

EricLiu0614 commented on Nov 28, 2022

@EricLiu0614

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

added a commit that references this issue on May 9, 2024
34fbf09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @paescuj@wojtekmaj@EricLiu0614@sherryzhang001

        Issue actions

          Can't find Page object in customTextRenderer layer prop on v6.0.3 (works on v5.7.2) · Issue #1190 · wojtekmaj/react-pdf