Class: ParsedPdfDocument
sempdf / ParsedPdfDocument
Defined in: src/parser.ts:316
A read-only parsed representation of a PDF document. It provides helpers for inspecting document-level metadata, object references, pages, forms, outlines, structure trees, and source bytes.
Constructors
Constructor
new ParsedPdfDocument(
version,
xrefOffsets,
trailer,
objects,
sourceBytes,
startXrefOffset,
encryption?,
recoveryMode?,
repairWarnings?): ParsedPdfDocument;Defined in: src/parser.ts:330
Creates a parsed PDF document wrapper around the trailer, cross-reference data, object table, source bytes, and optional encryption context.
Parameters
| Parameter | Type | Description |
|---|---|---|
version | string | The parsed PDF header version. |
xrefOffsets | ReadonlyMap<number, number> | The parsed cross-reference offsets by object id. |
trailer | PdfDict | The parsed trailer dictionary. |
objects | ReadonlyMap<number, ParsedPdfIndirectObject> | The parsed indirect objects by object id. |
sourceBytes | Uint8Array | The original source PDF bytes. |
startXrefOffset | number | The byte offset of the startxref pointer. |
encryption? | ParsedDocumentEncryption | The optional parsed encryption context. |
recoveryMode? | boolean | Whether the document was parsed in recovery mode. |
repairWarnings? | readonly string[] | Detailed repair warnings collected during recovery parsing. |
Returns
ParsedPdfDocument
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
lazyObjects | readonly | Set<number> | Set of object ids whose stream data has not yet been decoded. | src/parser.ts:354 |
recoveryMode? | readonly | boolean | Whether the document was parsed in recovery mode. | src/parser.ts:338 |
repairWarnings? | readonly | readonly string[] | Detailed repair warnings collected during recovery parsing. | src/parser.ts:339 |
startXrefOffset | readonly | number | The byte offset of the startxref pointer. | src/parser.ts:336 |
trailer | readonly | PdfDict | The parsed trailer dictionary. | src/parser.ts:333 |
version | readonly | string | The parsed PDF header version. | src/parser.ts:331 |
xrefOffsets | readonly | ReadonlyMap<number, number> | The parsed cross-reference offsets by object id. | src/parser.ts:332 |
Methods
extractText()
extractText(options?): readonly PageTextExtraction[];Defined in: src/parser.ts:665
Extracts positioned Unicode text from every page of the document. Best-effort: decodes each font via its /ToUnicode CMap when present and falls back to Latin-1 otherwise. Positions are user-space coordinates (origin lower-left) computed from the active text and graphics matrices.
Parameters
| Parameter | Type |
|---|---|
options | ExtractTextOptions |
Returns
readonly PageTextExtraction[]
Per-page text and positioned runs.
getConformanceProfile()
getConformanceProfile():
| DocumentConformanceProfile
| undefined;Defined in: src/parser.ts:602
Detects the supported PDF/A or PDF/UA conformance profile from catalog and XMP metadata.
Returns
| DocumentConformanceProfile
| undefined
The detected supported conformance profile, if any.
getEffectiveVersion()
getEffectiveVersion(): string;Defined in: src/parser.ts:470
Returns the effective PDF version, taking into account a Catalog /Version override that may raise the version above the file header.
Returns
string
getEncryptionContext()
getEncryptionContext(): PdfEncryptionContext | undefined;Defined in: src/parser.ts:517
Returns the parsed encryption context when the source PDF is encrypted.
Returns
PdfEncryptionContext | undefined
The encryption context, if present.
getEncryptionObjectId()
getEncryptionObjectId(): number | undefined;Defined in: src/parser.ts:526
Returns the Encrypt dictionary object id when one was parsed.
Returns
number | undefined
The encryption dictionary object id, if present.
getInfoObjectId()
getInfoObjectId(): number | undefined;Defined in: src/parser.ts:445
Returns the document information dictionary object id when one is present.
Returns
number | undefined
The information dictionary object id, if present.
getLanguage()
getLanguage(): string | undefined;Defined in: src/parser.ts:576
Returns the catalog language value when present.
Returns
string | undefined
The document language, if present.
getMaxObjectId()
getMaxObjectId(): number;Defined in: src/parser.ts:436
Returns the highest parsed object id, or zero for an empty object table.
Returns
number
The highest object id.
getMetadata()
getMetadata(): ParsedPdfMetadata;Defined in: src/parser.ts:535
Returns document information dictionary metadata.
Returns
The parsed document metadata.
getObject()
getObject(id):
| ParsedPdfIndirectObject
| undefined;Defined in: src/parser.ts:363
Returns a parsed indirect object by object id.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | number | The object id to look up. |
Returns
| ParsedPdfIndirectObject
| undefined
The parsed object, if present.
getObjectIds()
getObjectIds(): readonly number[];Defined in: src/parser.ts:427
Returns all parsed object ids sorted in ascending order.
Returns
readonly number[]
The sorted object ids.
getPageCount()
getPageCount(): number;Defined in: src/parser.ts:638
Returns the number of pages in the document.
Returns
number
The page count.
getPagesObjectId()
getPagesObjectId(): number;Defined in: src/parser.ts:499
Returns the root Pages tree object id.
Returns
number
The Pages tree object id.
getRepairWarnings()
getRepairWarnings(): readonly string[];Defined in: src/parser.ts:347
Returns the repair warnings collected during recovery parsing.
Returns
readonly string[]
The repair warnings, or an empty array.
getRootObjectId()
getRootObjectId(): number;Defined in: src/parser.ts:455
Returns the catalog object id from the trailer root entry.
Returns
number
The catalog object id.
getSourceBytes()
getSourceBytes(): Uint8Array;Defined in: src/parser.ts:508
Returns a defensive copy of the original source bytes.
Returns
Uint8Array
A copy of the source bytes.
getXmpMetadata()
getXmpMetadata(): string | undefined;Defined in: src/parser.ts:559
Returns decoded XMP metadata from the catalog metadata stream when present.
Returns
string | undefined
The decoded XMP metadata, if present.
inspectStructureElements()
inspectStructureElements(): readonly ParsedPdfInspectedStructureElement[];Defined in: src/parser.ts:827
Returns a nested inspection view of tagged structure elements.
Returns
readonly ParsedPdfInspectedStructureElement[]
The nested structure inspection records.
isTagged()
isTagged(): boolean;Defined in: src/parser.ts:585
Reports whether the document declares tagged PDF structure.
Returns
boolean
True when the document is tagged.
listAttachments()
listAttachments(): readonly ParsedPdfAttachment[];Defined in: src/parser.ts:756
Returns embedded file attachment metadata.
Returns
readonly ParsedPdfAttachment[]
The attachment metadata records.
listEditableStructureElements()
listEditableStructureElements(): readonly ParsedPdfEditableStructureElement[];Defined in: src/parser.ts:850
Returns editable handles for tagged structure elements.
Returns
readonly ParsedPdfEditableStructureElement[]
The editable structure element handles.
listFormFields()
listFormFields(): readonly ParsedPdfFormField[];Defined in: src/parser.ts:779
Returns AcroForm field metadata.
Returns
readonly ParsedPdfFormField[]
The parsed form fields.
listNamedDestinations()
listNamedDestinations(): readonly ParsedPdfNamedDestination[];Defined in: src/parser.ts:685
Returns named destinations discovered from the document name tree.
Returns
readonly ParsedPdfNamedDestination[]
The named destinations.
listOutlines()
listOutlines(): readonly ParsedPdfOutlineItem[];Defined in: src/parser.ts:708
Returns the document outline tree.
Returns
readonly ParsedPdfOutlineItem[]
The outline items.
listPageLabels()
listPageLabels(): readonly ParsedPdfPageLabelRange[];Defined in: src/parser.ts:735
Returns page-label ranges discovered from the page labels number tree.
Returns
readonly ParsedPdfPageLabelRange[]
The page-label ranges.
listPages()
listPages(): readonly ParsedPdfPage[];Defined in: src/parser.ts:650
Returns parsed page records discovered from the page tree.
Returns
readonly ParsedPdfPage[]
The parsed page records.
listStructureElements()
listStructureElements(): readonly ParsedPdfStructureElement[];Defined in: src/parser.ts:805
Returns a flat list of tagged structure elements.
Returns
readonly ParsedPdfStructureElement[]
The parsed structure elements.
preloadObjects()
preloadObjects(ids): void;Defined in: src/parser.ts:414
Eagerly loads and decodes the specified object ids so they are available without further lazy-parsing.
Parameters
| Parameter | Type | Description |
|---|---|---|
ids | readonly number[] | The object ids to preload. |
Returns
void