Skip to content

Commit 3a2df17

Browse files
committed
Add PdfPageObject.objectNumber
Add objectNumber:number to PdfPageObject and populate it from PDFium's EPDFDoc_GetPageObjectNumberByIndex. Update the PDFium engine bindings (functions, cjs/js glue and wasm), bump the pdfium submodule, and use the new call in openDocumentBuffer and importPages so page entries include their indirect-object number. Includes changesets for @embedpdf/engines and @embedpdf/models. The field will be 0 when PDFium cannot resolve the page dictionary (e.g. XFA pages).
1 parent 0d85365 commit 3a2df17

9 files changed

Lines changed: 31 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+
Populate `PdfPageObject.objectNumber` from PDFium's `EPDFDoc_GetPageObjectNumberByIndex` in `openDocumentBuffer` and `importPages`, so pages now expose their PDF indirect-object number alongside their index, size, and rotation.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@embedpdf/models': patch
3+
---
4+
5+
Add `objectNumber: number` to `PdfPageObject`, populated by the engine from `EPDFDoc_GetPageObjectNumberByIndex`. Lets consumers correlate pages with their PDF indirect-object numbers (e.g. for linking, debugging, or round-tripping raw object references). `PdfPageObject` is engine-owned — only the engine constructs it — so this is additive for all practical consumers.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ export class PdfiumNative implements IPdfiumExecutor {
384384
}
385385

386386
const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(docPtr, index) as Rotation;
387+
const objectNumber = this.pdfiumModule.EPDFDoc_GetPageObjectNumberByIndex(docPtr, index);
387388

388389
const page = {
389390
index,
@@ -392,6 +393,7 @@ export class PdfiumNative implements IPdfiumExecutor {
392393
height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, 'float'),
393394
},
394395
rotation,
396+
objectNumber,
395397
};
396398

397399
pages.push(page);
@@ -2738,6 +2740,10 @@ export class PdfiumNative implements IPdfiumExecutor {
27382740
destCtx.docPtr,
27392741
newPageIndex,
27402742
) as Rotation;
2743+
const objectNumber = this.pdfiumModule.EPDFDoc_GetPageObjectNumberByIndex(
2744+
destCtx.docPtr,
2745+
newPageIndex,
2746+
);
27412747

27422748
newPages.push({
27432749
index: newPageIndex,
@@ -2746,6 +2752,7 @@ export class PdfiumNative implements IPdfiumExecutor {
27462752
height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, 'float'),
27472753
},
27482754
rotation,
2755+
objectNumber,
27492756
});
27502757
}
27512758

packages/models/src/pdf.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export interface PdfPageObject {
2121
* Rotation of this page
2222
*/
2323
rotation: Rotation;
24+
25+
/**
26+
* PDF indirect-object number of this page's Page dictionary, as returned by
27+
* `EPDFDoc_GetPageObjectNumberByIndex`. Useful for correlating pages with
28+
* raw PDF references. Will be `0` when PDFium cannot resolve the page
29+
* dictionary (e.g. XFA pages, which have no `CPDF_Page`).
30+
*/
31+
objectNumber: number;
2432
}
2533

2634
/**

packages/pdfium/src/vendor/functions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const functions = {
116116
EPDFDest_CreateRemoteXYZ: [["number","number","boolean","number","boolean","number","boolean","number"] as const, 'number'] as const,
117117
EPDFDest_CreateView: [["number","number","number","number"] as const, 'number'] as const,
118118
EPDFDest_CreateXYZ: [["number","boolean","number","boolean","number","boolean","number"] as const, 'number'] as const,
119+
EPDFDoc_GetPageObjectNumberByIndex: [["number","number"] as const, 'number'] as const,
119120
EPDFDoc_LoadPageByObjectNumber: [["number","number"] as const, 'number'] as const,
120121
EPDFImageObj_SetJpeg: [["number","number","number","number","number"] as const, 'boolean'] as const,
121122
EPDFImageObj_SetPng: [["number","number","number","number","number"] as const, 'boolean'] as const,

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: 2 additions & 1 deletion
Large diffs are not rendered by default.
2.54 KB
Binary file not shown.

0 commit comments

Comments
 (0)