pdf-lite - v1.0.1
    Preparing search index...

    Represents a PDF document with support for reading, writing, and modifying PDF files. Handles document structure, revisions, encryption, and digital signatures.

    // Create a new document
    const document = new PdfDocument()

    // Read from bytes
    const document = await PdfDocument.fromBytes(fileBytes)

    // Add objects and commit
    document.add(pdfObject)
    await document.commit()

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    header: PdfComment = ...

    PDF version comment header

    modified: boolean = true

    Indicates whether the object has been modified. By default, assume it has been modified because it's a new object

    postTokens?: PdfToken[]

    Optional tokens to prepend or append during serialization

    preTokens?: PdfToken[]

    Optional tokens to prepend or append during serialization

    revisions: PdfRevision[]

    List of document revisions for incremental updates

    securityHandler?: PdfSecurityHandler

    Security handler for encryption/decryption operations

    signer: PdfSigner

    Signer instance for digital signature operations

    Accessors

    Methods

    • Commits pending objects to the document. Adds objects, applies encryption if configured, and updates the document structure.

      Parameters

      • ...newObjects: PdfObject[]

        Additional objects to add before committing

      Returns Promise<void>

    • Encrypts all objects in the document using the security handler. Creates and adds an encryption dictionary to all revisions.

      Returns Promise<void>

    • Reads and optionally decrypts an object by its object number. Handles both compressed and uncompressed objects.

      Parameters

      • options: { allowUnindexed?: boolean; generationNumber?: number; objectNumber: number }

        Object lookup options

        • OptionalallowUnindexed?: boolean

          If true, searches unindexed objects as fallback

        • OptionalgenerationNumber?: number

          Optional generation number filter

        • objectNumber: number

          The object number to find

      Returns Promise<PdfIndirectObject<PdfObject> | undefined>

      A cloned and decrypted copy of the object, or undefined if not found

    • Sets whether the document should use incremental updates. When true, locks all existing revisions to preserve original content.

      Parameters

      • value: boolean

        True to enable incremental mode, false to disable

      Returns void

    • Sets the owner password for document encryption.

      Parameters

      • ownerPassword: string

        The owner password to set

      Returns void

      Error if the security handler doesn't support password setting

    • Sets the user password for document encryption.

      Parameters

      • password: string

        The user password to set

      Returns void

      Error if the security handler doesn't support password setting

    • Sets the PDF version for the document.

      Parameters

      • version: string

        The PDF version string (e.g., '1.7', '2.0')

      Returns void

      Error if attempting to change version after objects have been added in incremental mode