Proper way to create a text element to display over the PDF's text #173
Unanswered
arun-mani-j
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hii, I'm trying to understand how to properly position a
span
element over the PDF's rendered page, so user can copy the text etc.This following script demonstrates how I get the "outer box" and font properties of a line block.
Then I convert each of these block into a
span
element. The span is styled like as follows (not actual CSS, just showing how I map the above values to the CSS values):It works fine, but I found that for some lines, the span element is larger than the PDF's text. For example, see the below picture for "This HOWTO discusses Python's..." line. I have shifted the Y coordinate a little above to make it easy to read. (The CSS is visible on right).
Here font-size is 9px (as returned by MuPDF). However if I use a value like 8.4px, then it fits properly.
I'm not able to understand what I'm doing wrong and why the span element's text is bigger than the PDF's text. Any help to understand it is highly appreciated.
The book used for reference is Python's HOWTO Unicode - https://docs.python.org/3/howto/unicode.html#unicode-howto (Can be downloaded as PDF from here https://docs.python.org/3/download.html).
A sample output of the script to get the text properties on the book (showing only last few elements):
Tl;dr: How to properly position a span element over a PDF page such that it properly fits the text underneath. 😅
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions