Skip to content

Commit a2b66e2

Browse files
committed
Add EPDFAnnot_GetRect with rect normalization.
1 parent a8d0591 commit a2b66e2

8 files changed

Lines changed: 20 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/engines': patch
3+
---
4+
5+
Update readPageAnnoRect to call EPDFAnnot_GetRect instead of FPDFAnnot_GetRect, ensuring annotation rectangles are always normalized. Fixes link annotations appearing below their expected position when the PDF Rect array has inverted y-coordinates.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/pdfium': patch
3+
---
4+
5+
Add EPDFAnnot_GetRect that wraps FPDFAnnot_GetRect with rect normalization. Upstream FPDFAnnot_GetRect does not normalize the rect read from the PDF dictionary, so when a PDF stores its Rect array with y1 > y2 the top/bottom values are inverted. This caused link annotations to be positioned incorrectly.

packages/engines/src/lib/pdfium/engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8307,7 +8307,7 @@ export class PdfiumNative implements IPdfiumExecutor {
83078307
right: 0,
83088308
bottom: 0,
83098309
};
8310-
if (this.pdfiumModule.FPDFAnnot_GetRect(annotationPtr, pageRectPtr)) {
8310+
if (this.pdfiumModule.EPDFAnnot_GetRect(annotationPtr, pageRectPtr)) {
83118311
pageRect.left = this.pdfiumModule.pdfium.getValue(pageRectPtr, 'float');
83128312
pageRect.top = this.pdfiumModule.pdfium.getValue(pageRectPtr + 4, 'float');
83138313
pageRect.right = this.pdfiumModule.pdfium.getValue(pageRectPtr + 8, 'float');

packages/pdfium/src/vendor/functions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const functions = {
6161
EPDFAnnot_GetOpacity: [['number', 'number'] as const, 'boolean'] as const,
6262
EPDFAnnot_GetOverlayText: [['number', 'number', 'number'] as const, 'number'] as const,
6363
EPDFAnnot_GetOverlayTextRepeat: [['number'] as const, 'boolean'] as const,
64+
EPDFAnnot_GetRect: [['number', 'number'] as const, 'boolean'] as const,
6465
EPDFAnnot_GetRectangleDifferences: [
6566
['number', 'number', 'number', 'number', 'number'] as const,
6667
'boolean',

packages/pdfium/src/vendor/pdfium.cjs

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

packages/pdfium/src/vendor/pdfium.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var createPdfium = (() => {
7070
'_EPDFAnnot_GetOpacity',
7171
'_EPDFAnnot_GetOverlayText',
7272
'_EPDFAnnot_GetOverlayTextRepeat',
73+
'_EPDFAnnot_GetRect',
7374
'_EPDFAnnot_GetRectangleDifferences',
7475
'_EPDFAnnot_GetReplyType',
7576
'_EPDFAnnot_GetRichContent',
@@ -6298,6 +6299,10 @@ var createPdfium = (() => {
62986299
'EPDFAnnot_GetUnrotatedRect',
62996300
2,
63006301
));
6302+
var _EPDFAnnot_GetRect = (Module['_EPDFAnnot_GetRect'] = createExportWrapper(
6303+
'EPDFAnnot_GetRect',
6304+
2,
6305+
));
63016306
var _EPDFAnnot_SetAPMatrix = (Module['_EPDFAnnot_SetAPMatrix'] = createExportWrapper(
63026307
'EPDFAnnot_SetAPMatrix',
63036308
3,
223 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)