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>

销毁当前对象。

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

枚举页面上对象的边界框。

Type declaration

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

      • filterArr: any[]

        用于指定要包含哪些对象的过滤数组。

      Returns Promise<any[]>

      返回页面上对象边界框的数组。

generateContent: () => Promise<void>

生成页面内容。

Type declaration

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

getBound: () => Promise<Rect>

获取页面的边界框。

Type declaration

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

      返回页面的边界框。

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

Gets the page dictionary.

Type declaration

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

获取与页面关联的文档。

Type declaration

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

      返回与页面关联的文档。

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

获取指定位置之后的下一个对象。

Type declaration

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

获取指定位置的对象。

Type declaration

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

通过索引获取对象。

Type declaration

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

      • index: number

        要获取的对象索引。

      Returns Promise<null | PageObjectType>

      返回指定索引处的 PageObject。

getObjectCount: () => Promise<number>

获取页面上的对象数量。

Type declaration

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

      返回页面上的对象数量。

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

获取指定对象的索引。

Type declaration

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

      Returns Promise<number>

      返回指定对象的索引。

getPageHeight: () => Promise<number>

获取页面高度。

Type declaration

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

      返回页面的高度。

getPageRotation: () => Promise<number>

获取页面旋转角度。

Type declaration

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

      返回页面的旋转角度。

getPageWidth: () => Promise<number>

获取页面宽度。

Type declaration

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

      返回页面的宽度。

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

获取指定位置之前的对象。

Type declaration

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

获取当前页面的文本页。

Type declaration

isParsed: () => Promise<boolean>

检查页面是否已被解析。

Type declaration

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

      如果页面已被解析则返回 true,否则返回 false。

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

构造一个页面。为了节省内存,可以禁用页面缓存功能,这样在页面渲染中使用的图像和蒙版将不会被缓存。当然,这会影响渲染速度。

Type declaration

    • (options: LoadPageType): Promise<void>
    • Parameters

      Returns Promise<void>

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>

将对象从一个位置移动到另一个位置。

Type declaration

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

批量更新指定对象的不透明度。

Type declaration

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

      • objectArr: string[]

        要更新的对象数组。

      • opacity: number

        要设置的不透明度值(0-100)。

      Returns Promise<boolean>

      如果操作成功则返回 true。

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

解析页面内容。

Type declaration

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

删除指定位置的对象。

Type declaration

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

      Returns Promise<void>

      当对象被删除时解析的 Promise。

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

根据对象的 ID 删除对象。

Type declaration

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

      • objId: string

        要删除的对象 ID。

      Returns Promise<boolean>

      如果对象被成功删除则返回 true。

Methods

  • 获取第一个对象的位置。

    Returns Promise<null | POSITIONType>

    返回第一个对象的位置。

    let pos = await page.getFirstObjectPosition();
    
  • 获取最后一个对象的位置。

    Returns Promise<null | POSITIONType>

    返回最后一个对象的位置。

  • 在指定位置之后插入一个对象。

    Parameters

    Returns Promise<null | POSITIONType>

    返回插入对象的位置。

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