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:
- Create an instance with
NotoPdf.init() - Open PDFs with
openPdf() - Render pages with the returned
PdfDocument - 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 exitsdestroy()
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
File path, Buffer, Uint8Array, or ArrayBuffer
options?
Options for opening the PDF (password, etc.)
Returns
Promise<PdfDocument>
Promise resolving to a PdfDocument instance
Example
// From file pathconst pdf = await notoPdf.openPdf('/path/to/document.pdf')
// From Bufferconst buffer = await fs.readFile('/path/to/document.pdf')const pdf = await notoPdf.openPdf(buffer)
// With passwordconst 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
Array of font configurations to register
Returns
void
Example
const notoPdf = await NotoPdf.init()
// Add fonts later based on document analysisif (needsJapaneseFont) { notoPdf.registerFonts([await loadFontJp()])}init()
staticinit(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?
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 fontsconst notoPdf = await NotoPdf.init({ fonts: [await loadFontJp()]})