diff --git a/src/index.ts b/src/index.ts index d01764a..0dae3eb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import sharp from 'sharp'; -import pdfium from './vendor/pdfium'; +import vendor from './vendor/pdfium'; +import type * as t from './vendor/pdfium'; const BYTES_PER_PIXEL = 4; @@ -73,9 +74,9 @@ export type PDFiumPageRender = { }; export class PDFiumLibrary { - module: any; + module: t.PDFium; static async init() { - const module = await pdfium(); + const module = await vendor(); module._FPDF_InitLibraryWithConfig({ version: 2, m_pIsolate: null, @@ -87,7 +88,7 @@ export class PDFiumLibrary { return new PDFiumLibrary(module); } - constructor(module: any) { + constructor(module: t.PDFium) { this.module = module; } @@ -112,10 +113,10 @@ export class PDFiumLibrary { } export class PDFiumDocument { - module: any; - documentPointer: any; + module: t.PDFium; + documentPointer: number; documentHandle: any; - constructor(module: any, documentPointer: any, documentHandle: any) { + constructor(module: t.PDFium, documentPointer: number, documentHandle: any) { this.module = module; this.documentPointer = documentPointer; this.documentHandle = documentHandle; diff --git a/src/vendor/pdfium.d.ts b/src/vendor/pdfium.d.ts index 0e49a45..768f6fc 100644 --- a/src/vendor/pdfium.d.ts +++ b/src/vendor/pdfium.d.ts @@ -1,4 +1,4 @@ -declare type PDFium = { +export declare type PDFium = { _FPDF_InitLibraryWithConfig: (config: any) => void; _FPDF_LoadMemDocument: (ptr: number, size: number, password: string) => any; _FPDF_GetLastError: () => number; @@ -21,6 +21,7 @@ declare type PDFium = { flags: number ) => void; _FPDFBitmap_Destroy: (bitmap: any) => void; + _FPDF_CloseDocument(document: any): void; asm: { malloc: (size: number) => number; free: (ptr: number) => void; @@ -28,6 +29,6 @@ declare type PDFium = { HEAPU8: Uint8Array; }; -declare function loadPdfium(): Promise; +export declare function loadPdfium(): Promise; export default loadPdfium;