[Bug]: TextLayer not rendering properly #19386
Replies: 4 comments
|
I encountered the same problem! |
|
I got the same issue. In my case, I'm getting empty spaces along with normal words, when reading textContent. let textContent = await page.getTextContent();. After ignoring items with empty spaces, my issue is resolved. |
SolutionI encountered the same issue where the text layer was not aligned with the canvas layer. A straightforward fix is to import the default PDF.js viewer stylesheet: import 'pdfjs-dist/web/pdf_viewer.css'This correctly aligns the text layer with the rendered canvas. Potential IssueImporting Alternative ApproachTo avoid global style conflicts, I extracted only the This keeps the text layer properly aligned while preventing the rest of the PDF.js viewer styles from affecting the application. Hope this helps! 👍 |

Uh oh!
There was an error while loading. Please reload this page.
Attach (recommended) or Link to PDF file
https://arxiv.org/pdf/2408.09869
Web browser and its version
Chrome Version 132.0.6834.110 (Official Build) (64-bit)
Operating system and its version
Debian 12.6
PDF.js version
v4.10.38
Is the bug present in the latest PDF.js version?
Yes
Is a browser extension
No
Steps to reproduce the problem
I'm Using pdfjs in svelte but I can't seem to get the text layer to render properly.
Here's the output when I select the text:
I cant find any docs related to the TextLayer API. Some fresh working example will help alot!
What is the expected behavior?
When viewing in firefox everything works perfectly.
What went wrong?
Trying to select text is painful
Link to a viewer
No response
Additional context
No response
All reactions