Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unable to get the style of each span element which we got it in react pdf 5 version #1937

Open
4 tasks done
NiharikaSrinivasa opened this issue Jan 23, 2025 · 0 comments
Open
4 tasks done
Labels
bug Something isn't working

Comments

@NiharikaSrinivasa
Copy link

NiharikaSrinivasa commented Jan 23, 2025

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

Its a blocker for me in my project, need help on this

I was using version 5 of React-PDF to render a file, and my goal was to fetch the x and y coordinates of the selected text on the PDF.

To achieve this, I used the element.style of the span elements, which provided the top and left attributes in px for the selected text.

Recently, I upgraded to React-PDF version 9, where the top and left attributes of each span style are now provided in percentages (%) instead of px.

Could you share how to obtain these attributes in px, or suggest a method to convert the percentage-based coordinates to px?

Steps to reproduce

Inspect the page that renders the PDF.
View the span tags corresponding to the text in the PDF.
Check the element.style of span tag.

Expected behavior

react-pdf 5 version result of span attribute which i used to generate x and y coordinate:

element.style {
height: 1em;
font-family: Helvetica, sans-serif;
font-size: 38px;
position: absolute;
top: 182.33px;
left: 158.12px;
transform-origin: left bottom;
white-space: pre;
pointer-events: all;
}

styles in px of top and left attribute, else suggestion to fetch in px / for conversion to px.

Actual behavior

react-pdf version 9 / latest version's result :

element.style {
left: 26.57%;
top: 22.47%;
font-size: calc(var(--scale-factor)* 38.00px);
font-family: sans-serif;
transform: scaleX(1.01528);
}

Additional information

No response

Environment

  • Browser (if applicable): Chrome
  • React-PDF version: 9
  • React version: 18
  • Bundler name and version (if applicable):
@NiharikaSrinivasa NiharikaSrinivasa added the bug Something isn't working label Jan 23, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant