Skip to content

Commit cf22b95

Browse files
authored
Merge pull request #641 from embedpdf/feature/add-page-object-number
Add PdfPageObject.objectNumber
2 parents 146cde1 + 78c22e1 commit cf22b95

4 files changed

Lines changed: 25 additions & 0 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
/**

0 commit comments

Comments
 (0)