コンテンツにスキップ

PDFiumLibrary

このコンテンツはまだ日本語訳がありません。

Defined in: packages/core/src/pdfium/library.ts:42

PDFium library instance.

Low-level wrapper around the PDFium WASM module. Manages the lifecycle of the WASM module and provides document loading capabilities.

Note: For most use cases, prefer using NotoPdf which provides a higher-level, more user-friendly API.

Important: Only create one instance per process. Creating multiple instances will load multiple copies of the WASM module, consuming significant memory.

Example

// Low-level usage (advanced)
const library = await PDFiumLibrary.init()
library.registerFonts([await loadFontJp()])
const doc = library.loadDocument(pdfData)
// ... use doc ...
doc.destroy()
library.destroy()

Methods

destroy()

destroy(): void

Defined in: packages/core/src/pdfium/library.ts:246

Destroys the library and frees resources.

Returns

void


getModule()

getModule(): PDFiumModule

Defined in: packages/core/src/pdfium/library.ts:56

Gets the underlying PDFium module. Use with caution - this is for advanced use cases like font registration.

Returns

PDFiumModule


loadDocument()

loadDocument(data, password?): PDFiumDocument

Defined in: packages/core/src/pdfium/library.ts:192

Loads a PDF document.

Parameters

data

Uint8Array

PDF data as Uint8Array

password?

string

Optional password for encrypted PDFs

Returns

PDFiumDocument

Promise resolving to a PDFiumDocument


registerFonts()

registerFonts(fonts, directory): void

Defined in: packages/core/src/pdfium/library.ts:103

Registers fonts in the library’s virtual filesystem.

This is primarily useful for the lite variant where fonts are not embedded.

Parameters

fonts

FontConfig[]

Array of font configurations

directory

string = DEFAULT_FONT_DIR

Directory to place fonts (default: /fonts)

Returns

void


init()

static init(): Promise<PDFiumLibrary>

Defined in: packages/core/src/pdfium/library.ts:85

Initializes a new PDFium library instance.

Each call creates a new, independent instance with its own WASM module. You are responsible for calling destroy() when done to free resources.

Important: Only create one instance per process to avoid memory issues.

The core library does not include embedded fonts. Use font packages (e.g., @noto-pdf-ts/fonts-jp) and registerFonts() to add fonts manually if needed for rendering PDFs without embedded fonts.

Returns

Promise<PDFiumLibrary>

Promise resolving to a new PDFiumLibrary instance

Example

import { PDFiumLibrary } from '@noto-pdf-ts/core'
import loadFontJp from '@noto-pdf-ts/fonts-jp'
const library = await PDFiumLibrary.init()
library.registerFonts([await loadFontJp()])
// ... use library ...
library.destroy()