Skip to content

NotoPdf

Defined in: packages/core/src/noto-pdf.ts:105

High-level API for PDF rendering with font support.

NotoPdf provides a clean, type-safe interface for opening PDFs and rendering them to images. It manages the underlying PDFium library and font registration.

Usage:

  1. Create an instance with NotoPdf.init()
  2. Open PDFs with openPdf()
  3. Render pages with the returned PdfDocument
  4. Call destroy() when done to free resources

Examples

Basic usage:

import { NotoPdf } from '@noto-pdf-ts/core'
import loadFontJp from '@noto-pdf-ts/fonts-jp'
const notoPdf = await NotoPdf.init({ fonts: [await loadFontJp()] })
const pdf = await notoPdf.openPdf('/path/to/document.pdf')
for await (const page of pdf.renderPages()) {
await fs.writeFile(`page-${page.pageNumber}.jpg`, page.buffer)
}
await pdf.close()
notoPdf.destroy()

Processing multiple PDFs:

const notoPdf = await NotoPdf.init({ fonts: [await loadFontJp()] })
for (const file of pdfFiles) {
const pdf = await notoPdf.openPdf(file)
for await (const page of pdf.renderPages()) {
// Process pages...
}
await pdf.close()
}
notoPdf.destroy()

Methods

[asyncDispose]()

[asyncDispose](): Promise<void>

Defined in: packages/core/src/noto-pdf.ts:232

Implements AsyncDisposable for use with await using.

Returns

Promise<void>

Example

await using notoPdf = await NotoPdf.init({ fonts: [await loadFontJp()] })
const pdf = await notoPdf.openPdf('document.pdf')
// ... use pdf ...
// notoPdf.destroy() is called automatically when scope exits

destroy()

destroy(): void

Defined in: packages/core/src/noto-pdf.ts:213

Destroys the instance and frees all resources.

After calling this method, the instance cannot be used anymore. This method is idempotent (safe to call multiple times).

Returns

void

Example

const notoPdf = await NotoPdf.init()
// ... use notoPdf ...
notoPdf.destroy()

openPdf()

openPdf(input, options?): Promise<PdfDocument>

Defined in: packages/core/src/noto-pdf.ts:195

Opens a PDF document for rendering.

The returned PdfDocument must be closed when done using close() or the await using syntax.

Parameters

input

PdfInput

File path, Buffer, Uint8Array, or ArrayBuffer

options?

OpenPdfOptions

Options for opening the PDF (password, etc.)

Returns

Promise<PdfDocument>

Promise resolving to a PdfDocument instance

Example

// From file path
const pdf = await notoPdf.openPdf('/path/to/document.pdf')
// From Buffer
const buffer = await fs.readFile('/path/to/document.pdf')
const pdf = await notoPdf.openPdf(buffer)
// With password
const pdf = await notoPdf.openPdf('/path/to/encrypted.pdf', {
password: 'secret'
})
// Using await using (auto-close)
await using pdf = await notoPdf.openPdf('document.pdf')

registerFonts()

registerFonts(fonts): void

Defined in: packages/core/src/noto-pdf.ts:162

Registers additional fonts after initialization.

Use this method when you need to add fonts dynamically, for example based on detected PDF content.

Parameters

fonts

FontConfig[]

Array of font configurations to register

Returns

void

Example

const notoPdf = await NotoPdf.init()
// Add fonts later based on document analysis
if (needsJapaneseFont) {
notoPdf.registerFonts([await loadFontJp()])
}

init()

static init(options?): Promise<NotoPdf>

Defined in: packages/core/src/noto-pdf.ts:133

Initializes NotoPdf with optional font configuration.

Each call creates a new, independent instance. You are responsible for calling destroy() when done.

Parameters

options?

NotoPdfOptions

Initialization options including fonts

Returns

Promise<NotoPdf>

Promise resolving to a new NotoPdf instance

Example

// Without fonts (for PDFs with embedded fonts)
const notoPdf = await NotoPdf.init()
// With Japanese fonts
const notoPdf = await NotoPdf.init({
fonts: [await loadFontJp()]
})