sempdf

Class: ParsedPdfDocument

sempdf v1.9.1


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

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.src/parser.ts:354
recoveryMode?readonlybooleanWhether the document was parsed in recovery mode.src/parser.ts:338
repairWarnings?readonlyreadonly string[]Detailed repair warnings collected during recovery parsing.src/parser.ts:339
startXrefOffsetreadonlynumberThe byte offset of the startxref pointer.src/parser.ts:336
trailerreadonlyPdfDictThe parsed trailer dictionary.src/parser.ts:333
versionreadonlystringThe parsed PDF header version.src/parser.ts:331
xrefOffsetsreadonlyReadonlyMap<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

ParameterType
optionsExtractTextOptions

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

ParsedPdfMetadata

The parsed document metadata.


getObject()

getObject(id): 
  | ParsedPdfIndirectObject
  | undefined;

Defined in: src/parser.ts:363

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[];

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

ParameterTypeDescription
idsreadonly number[]The object ids to preload.

Returns

void

On this page