Skip to main content

Class: ParsedPdfDocument

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;

Creates a parsed PDF document wrapper around the trailer, cross-reference data, object table, source bytes, and optional encryption context.

Parameters​

ParameterTypeDescription
versionstringThe parsed PDF header version.
xrefOffsetsReadonlyMap<number, number>The parsed cross-reference offsets by object id.
trailerPdfDictThe parsed trailer dictionary.
objectsReadonlyMap<number, ParsedPdfIndirectObject>The parsed indirect objects by object id.
sourceBytesUint8ArrayThe original source PDF bytes.
startXrefOffsetnumberThe byte offset of the startxref pointer.
encryption?ParsedDocumentEncryptionThe optional parsed encryption context.
recoveryMode?booleanWhether the document was parsed in recovery mode.
repairWarnings?readonly string[]Detailed repair warnings collected during recovery parsing.

Returns​

ParsedPdfDocument

Properties​

PropertyModifierTypeDescriptionDefined in
lazyObjectsreadonlySet<number>Set of object ids whose stream data has not yet been decoded.
recoveryMode?readonlybooleanWhether the document was parsed in recovery mode.
repairWarnings?readonlyreadonly string[]Detailed repair warnings collected during recovery parsing.
startXrefOffsetreadonlynumberThe byte offset of the startxref pointer.
trailerreadonlyPdfDictThe parsed trailer dictionary.
versionreadonlystringThe parsed PDF header version.
xrefOffsetsreadonlyReadonlyMap<number, number>The parsed cross-reference offsets by object id.

Methods​

extractText()​

extractText(options?): readonly PageTextExtraction[];

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​

ParameterType
optionsExtractTextOptions

Returns​

readonly PageTextExtraction[]

Per-page text and positioned runs.


getConformanceProfile()​

getConformanceProfile(): 
| DocumentConformanceProfile
| undefined;

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;

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;

Returns the parsed encryption context when the source PDF is encrypted.

Returns​

PdfEncryptionContext | undefined

The encryption context, if present.


getEncryptionObjectId()​

getEncryptionObjectId(): number | undefined;

Returns the Encrypt dictionary object id when one was parsed.

Returns​

number | undefined

The encryption dictionary object id, if present.


getInfoObjectId()​

getInfoObjectId(): number | undefined;

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;

Returns the catalog language value when present.

Returns​

string | undefined

The document language, if present.


getMaxObjectId()​

getMaxObjectId(): number;

Returns the highest parsed object id, or zero for an empty object table.

Returns​

number

The highest object id.


getMetadata()​

getMetadata(): ParsedPdfMetadata;

Returns document information dictionary metadata.

Returns​

ParsedPdfMetadata

The parsed document metadata.


getObject()​

getObject(id): 
| ParsedPdfIndirectObject
| undefined;

Returns a parsed indirect object by object id.

Parameters​

ParameterTypeDescription
idnumberThe object id to look up.

Returns​

| ParsedPdfIndirectObject | undefined

The parsed object, if present.


getObjectIds()​

getObjectIds(): readonly number[];

Returns all parsed object ids sorted in ascending order.

Returns​

readonly number[]

The sorted object ids.


getPageCount()​

getPageCount(): number;

Returns the number of pages in the document.

Returns​

number

The page count.


getPagesObjectId()​

getPagesObjectId(): number;

Returns the root Pages tree object id.

Returns​

number

The Pages tree object id.


getRepairWarnings()​

getRepairWarnings(): readonly string[];

Returns the repair warnings collected during recovery parsing.

Returns​

readonly string[]

The repair warnings, or an empty array.


getRootObjectId()​

getRootObjectId(): number;

Returns the catalog object id from the trailer root entry.

Returns​

number

The catalog object id.


getSourceBytes()​

getSourceBytes(): Uint8Array;

Returns a defensive copy of the original source bytes.

Returns​

Uint8Array

A copy of the source bytes.


getXmpMetadata()​

getXmpMetadata(): string | undefined;

Returns decoded XMP metadata from the catalog metadata stream when present.

Returns​

string | undefined

The decoded XMP metadata, if present.


inspectStructureElements()​

inspectStructureElements(): readonly ParsedPdfInspectedStructureElement[];

Returns a nested inspection view of tagged structure elements.

Returns​

readonly ParsedPdfInspectedStructureElement[]

The nested structure inspection records.


isTagged()​

isTagged(): boolean;

Reports whether the document declares tagged PDF structure.

Returns​

boolean

True when the document is tagged.


listAttachments()​

listAttachments(): readonly ParsedPdfAttachment[];

Returns embedded file attachment metadata.

Returns​

readonly ParsedPdfAttachment[]

The attachment metadata records.


listEditableStructureElements()​

listEditableStructureElements(): readonly ParsedPdfEditableStructureElement[];

Returns editable handles for tagged structure elements.

Returns​

readonly ParsedPdfEditableStructureElement[]

The editable structure element handles.


listFormFields()​

listFormFields(): readonly ParsedPdfFormField[];

Returns AcroForm field metadata.

Returns​

readonly ParsedPdfFormField[]

The parsed form fields.


listNamedDestinations()​

listNamedDestinations(): readonly ParsedPdfNamedDestination[];

Returns named destinations discovered from the document name tree.

Returns​

readonly ParsedPdfNamedDestination[]

The named destinations.


listOutlines()​

listOutlines(): readonly ParsedPdfOutlineItem[];

Returns the document outline tree.

Returns​

readonly ParsedPdfOutlineItem[]

The outline items.


listPageLabels()​

listPageLabels(): readonly ParsedPdfPageLabelRange[];

Returns page-label ranges discovered from the page labels number tree.

Returns​

readonly ParsedPdfPageLabelRange[]

The page-label ranges.


listPages()​

listPages(): readonly ParsedPdfPage[];

Returns parsed page records discovered from the page tree.

Returns​

readonly ParsedPdfPage[]

The parsed page records.


listStructureElements()​

listStructureElements(): readonly ParsedPdfStructureElement[];

Returns a flat list of tagged structure elements.

Returns​

readonly ParsedPdfStructureElement[]

The parsed structure elements.


preloadObjects()​

preloadObjects(ids): void;

Eagerly loads and decodes the specified object ids so they are available without further lazy-parsing.

Parameters​

ParameterTypeDescription
idsreadonly number[]The object ids to preload.

Returns​

void