Replies: 2 comments 2 replies
-
I'm in a similar situation. I process PDFs with PDFbox in the Backend, which returns TextPositions as coordinates but I can't find a way to draw those rectangles correctly in the frontend, as the coordinates in the PDFviewer don't match the ones from PDFbox, even if I try to calculate with the scales provided. |
Beta Was this translation helpful? Give feedback.
-
Sorry for responding late - for some reason unknown, your question slipped my attention. The constant offset of 17.6 pixels (?) sounds like a CSS issue. Maybe the page is smaller than you expect it to be because there's a padding or margin reducing the available space. Can you check this? Does it get better if you set As for improving the alignment of the text layer: I'm afraid I'm not the expert here. You're right, in theory it should be possible to generate a perfect text layer. The PDF viewer renders the page correctly, so it obviously knows the precise coordinates. It just fails to tell the HTML layer about it. I suspect that's difficult because the canvas is rendered in the worker thread, while the text layer is rendered in the main thread, but it's just guesswork. The only thing I know for sure is that the text layer has to use one of the fonts the browser knows, and that's usually not the font the PDF file uses. If you'd like to try to improve the alignment of the text layer yourself, I'd point you to @ Timvandermeij. I'm not sure whether he's the expert, but he knows who the expert is, so he's probably a good contact. If you're ready to submit a pull request, just tell me, and I'll introduce you to Tim. |
Beta Was this translation helpful? Give feedback.
-
@stephanrauh and community - Hi. I'm building an app that can programmatically add annotations to a pdf file, based on ngx-extended-pdf-viewer and another library highKite/pdfAnnotate. Previous discussions can be found here #2090 and here #2117 just for background. Also, to clarify and isolate the problems, the locating issue I describe here does not involve the highKite/pdfAnnotate library - it simply takes coordinates, size, color, etc. as input and draw the annotations. According to my check, it draws the annotations at correct locations on the pdf pages according to the input data. So the focus is how to find something in a pdf web viewer - ngx-extended-pdf-viewer in this case, report the coordinates in viewer and convert that to coordinates on pdf pages.
Please see snapshot below - I'm searching for "framework" as an example.
Questions -
- I do have a suspicion that the offset might be due to the difference between
pdfPageElement.getBoundingClientRect()
and theoretic page size in viewport. I tested with a 8.5in * 11in document and different zoom/viewport scale settings. As shown in the 2nd snapshot, the "theoretic" page width should be 8.5" * 72 DPI * Column B view scale. However, the actual width got frompdfPageElement.getBoundingClientRect().width
(Column C) is always 17.6 more, no matter the viewport scale. This could also explain that the more I zoom in (like 400% as against to 50%), the closer the annotations are from the target, because the constant 17.6 becomes relatively insignificant compared to the increased viewport size. Is there a padding/margin that's causing this? However I really have no idea and don't want to mislead others if this is not the reason.Snapshot 1 - offset of the annotations placed:
Snapshot 2 - chart of actual pdf page width in viewport vs. theoretical pdf page width in viewport:
pdf file used in test:
user-experience.pdf
my test-1.component.html:
test-1.component.ts:
test-1.component.css:
Beta Was this translation helpful? Give feedback.
All reactions