WebViewer Version: 11.5.0
Do you have an issue with a specific file(s)?
No but I can attach an example
8mb_minified.pdf (18.3 KB)
Can you reproduce using one of our samples or online demos?
No
Are you using the WebViewer server?
No
Does the issue only happen on certain browsers?
No
Is your issue related to a front-end framework?
No
Is your issue related to annotations?
No
Please give a brief summary of your issue:
Element.updateTextMetrics()
incorrectly inserts identity Tm
, overriding intended Td
position
Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
Description and Steps to Reproduce
Iām modifying text elements using the WebViewer full API. The general approach is:
- Remove an existing
textElement
. - Create a new one with new text.
- Reposition it based on the original bounding box.
- Call
updateTextMetrics()
to finalize the geometry.
This works in many cases, but on PDFs that use Td
positioning (rather than Tm
), the output is incorrect. Specifically, updateTextMetrics()
inserts an identity Tm
(1 0 0 1 0 0
), which overrides the effect of the preceding Td
and causes the text to render at the origin instead of the correct position.
Input Code Example
const bbox = oldElement.getBBox();
const matrix = await Core.PDFNet.Matrix2D.create(1, 0, 0, 1, bbox.x1, bbox.y1);
await newElement.setTextMatrix(matrix);
await newElement.updateTextMetrics();
Generated Output (Incorrect)
BT
42.52 727.045 Td
0 J
1 w
1 0 0 1 0 0 Tm ā inserted by `updateTextMetrics()`
/F1 11 Tf
(GAVE HER ONE, GAVE HIM TWO...) Tj
ET
Expected Output
BT
42.52 727.045 Td
0 J
1 w
/F1 11 Tf
(GAVE HER ONE, GAVE HIM TWO...) Tj
ET
Why This Is a Problem
By inserting 1 0 0 1 0 0 Tm
, updateTextMetrics()
cancels the effect of the prior Td
, causing the text to render at (0,0)
instead of the correct position set by Td
. This makes it impossible to rely on Td
positioning once updateTextMetrics()
is called, breaking previously valid layout code.
Please let me know if thereās a workaround because I canāt find a way to update text matrix correctly for all PDFs. Thanks!
Workaround Attempt
I tried the following to avoid calling updateTextMetrics()
when the original element uses Td
:
if (oldElement.hasTextMatrix()) {
await newElement.updateTextMetrics();
}
But this fails for other PDFs, so itās not a reliable solution across all documents.
Please provide a link to a minimal sample where the issue is reproducible:
N/A