interface PageType {
    destroy: () => Promise<void>;
    enumObjectsBBox: (filterArr: any[]) => Promise<any[]>;
    generateContent: () => Promise<void>;
    getBound: () => Promise<Rect>;
    getDict: () => Promise<null | PDFDictionaryType>;
    getDoc: () => Promise<null | DocType>;
    getNextPosition: (position: POSITIONType) => Promise<null | POSITIONType>;
    getObjectAt: (position: POSITIONType) => Promise<null | PageObjectType>;
    getObjectByIndex: (index: number) => Promise<null | PageObjectType>;
    getObjectCount: () => Promise<number>;
    getObjectIndex: (obj: PageObjectType) => Promise<number>;
    getPageHeight: () => Promise<number>;
    getPageRotation: () => Promise<number>;
    getPageWidth: () => Promise<number>;
    getPrevPosition: (position: POSITIONType) => Promise<null | POSITIONType>;
    getTextPage: () => Promise<null | TextPageType>;
    isParsed: () => Promise<boolean>;
    load: (options: LoadPageType) => Promise<void>;
    moveObject: (
        position: POSITIONType,
        newPosAfter: POSITIONType,
    ) => Promise<null | POSITIONType>;
    opacityBatchUpdate: (
        objectArr: string[],
        opacity: number,
    ) => Promise<boolean>;
    options: Options;
    parseContent: (options: ParseOptionsType) => Promise<void>;
    removeObject: (position: POSITIONType) => Promise<void>;
    removeObjectById: (objId: string) => Promise<boolean>;
    getFirstObjectPosition(): Promise<null | POSITIONType>;
    getLastObjectPosition(): Promise<null | POSITIONType>;
    insertObject(
        posInsertAfter: POSITIONType,
        newObj: InsertObjectType,
    ): Promise<null | POSITIONType>;
}

Implemented by

Properties

destroy: () => Promise<void>

Destroy the current object.

enumObjectsBBox: (filterArr: any[]) => Promise<any[]>

Enumerate the bounding boxes of the objects on the page.

Type declaration

    • (filterArr: any[]): Promise<any[]>
    • Parameters

      • filterArr: any[]

        The filter array to specify which objects to include.

      Returns Promise<any[]>

      Returns an array of bounding boxes of the objects on the page.

generateContent: () => Promise<void>

Generate the content of the page.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

getBound: () => Promise<Rect>

Get the bounding box of the page.

Type declaration

    • (): Promise<Rect>
    • Returns Promise<Rect>

      Return the bounding box of the page.

getDict: () => Promise<null | PDFDictionaryType>

Gets the page dictionary.

Type declaration

getDoc: () => Promise<null | DocType>

Get the document associated with the page.

Type declaration

    • (): Promise<null | DocType>
    • Returns Promise<null | DocType>

      Returns the document associated with the page.

getNextPosition: (position: POSITIONType) => Promise<null | POSITIONType>

Get the next object after the specified position.

Type declaration

getObjectAt: (position: POSITIONType) => Promise<null | PageObjectType>

Get the object at the specified position.

Type declaration

getObjectByIndex: (index: number) => Promise<null | PageObjectType>

Get the object by index.

Type declaration

    • (index: number): Promise<null | PageObjectType>
    • Parameters

      • index: number

        The index of the object to get.

      Returns Promise<null | PageObjectType>

      Return the PageObject at the specified index.

getObjectCount: () => Promise<number>

Get the number of objects on the page.

Type declaration

    • (): Promise<number>
    • Returns Promise<number>

      Return the number of objects on the page.

getObjectIndex: (obj: PageObjectType) => Promise<number>

Get the index of the specified object.

Type declaration

    • (obj: PageObjectType): Promise<number>
    • Parameters

      Returns Promise<number>

      Return the index of the specified object.

getPageHeight: () => Promise<number>

Get the page height.

Type declaration

    • (): Promise<number>
    • Returns Promise<number>

      Returns the height of the page.

getPageRotation: () => Promise<number>

Get the page rotation.

Type declaration

    • (): Promise<number>
    • Returns Promise<number>

      Returns the rotation of the page.

getPageWidth: () => Promise<number>

Get the page width.

Type declaration

    • (): Promise<number>
    • Returns Promise<number>

      Returns the width of the page.

getPrevPosition: (position: POSITIONType) => Promise<null | POSITIONType>

Get the previous object before the specified position.

Type declaration

getTextPage: () => Promise<null | TextPageType>

Get the text page of the current page.

Type declaration

isParsed: () => Promise<boolean>

Check if the page has been parsed.

Type declaration

    • (): Promise<boolean>
    • Returns Promise<boolean>

      Return true if the page has been parsed, otherwise return false.

let isParsed = await page.isParsed();
if (isParsed === false) {
await page.parseContent();
load: (options: LoadPageType) => Promise<void>

Construct a page. For saving memory, the page caching feature can be disabled, then images and masks used in page rendering won't be cached. Of course this will affect the speed.

Type declaration

let page = await Page.create();
if (page === null) {
throw new Error('Create page failed');
}
await page.load({doc: doc, pageDict: pageDict, pageCache: true
moveObject: (
    position: POSITIONType,
    newPosAfter: POSITIONType,
) => Promise<null | POSITIONType>

Move the object from one position to another.

Type declaration

    • (
          position: POSITIONType,
          newPosAfter: POSITIONType,
      ): Promise<null | POSITIONType>
    • Parameters

      • position: POSITIONType

        The position of the object to be moved.

      • newPosAfter: POSITIONType

        The new position after which the object is moved.

      Returns Promise<null | POSITIONType>

      A promise that resolves to the new position of the moved object.

opacityBatchUpdate: (objectArr: string[], opacity: number) => Promise<boolean>

Batch update the opacity of the specified objects.

Type declaration

    • (objectArr: string[], opacity: number): Promise<boolean>
    • Parameters

      • objectArr: string[]

        The array of objects to update.

      • opacity: number

        The opacity value to set (0-100).

      Returns Promise<boolean>

      Returns true if the operation was successful.

options: Options
parseContent: (options: ParseOptionsType) => Promise<void>

Parse the content of the page.

Type declaration

removeObject: (position: POSITIONType) => Promise<void>

Remove the object at the specified position.

Type declaration

    • (position: POSITIONType): Promise<void>
    • Parameters

      • position: POSITIONType

        The position of the object to be removed.

      Returns Promise<void>

      A promise that resolves when the object has been removed.

removeObjectById: (objId: string) => Promise<boolean>

Remove an object by its ID.

Type declaration

    • (objId: string): Promise<boolean>
    • Parameters

      • objId: string

        The ID of the object to remove.

      Returns Promise<boolean>

      Returns true if the object was successfully removed.

Methods

  • Get the position of first object.

    Returns Promise<null | POSITIONType>

    Return the position of first object.

    let pos = await page.getFirstObjectPosition();
    
  • Get the position of last object.

    Returns Promise<null | POSITIONType>

    Return the position of last object.

  • Insert an object after the specified position.

    Parameters

    Returns Promise<null | POSITIONType>

    Return the position of the inserted object.

    let pos = await page.getLastObjectPosition();
    let newObj = await TextObject.create();
    await page.insertObject(pos, newObj);