Skip to main content

API Reference

PDFDocument

The main entry point. Open PDFs and access pages, metadata, search, and full-tier features.

PDFDocument.open(source, options?)

Open a PDF from any supported source.

const doc = await PDFDocument.open("/report.pdf");
const doc = await PDFDocument.open(arrayBuffer);
const doc = await PDFDocument.open(file, { password: "secret" });

Parameters:

ParameterTypeDescription
sourcestring | ArrayBuffer | Uint8Array | File | BlobPDF source — URL, buffer, File, Blob, or base64 data URI

Options:

OptionTypeDefaultDescription
passwordstringPassword for encrypted PDFs
headersRecord<string, string>HTTP headers for URL fetching
credentialsRequestCredentialsFetch credentials mode
wasmUrlstringjsDelivr CDNCustom WASM binary URL

Returns: Promise<PDFDocument>


Properties

PropertyTypeDescription
.pageCountnumberTotal number of pages
.metadataPDFMetadataDocument metadata (title, author, etc.)
.outlineOutlineItem[]Bookmark/TOC tree
.permissionsPDFPermissionsDocument permissions
.isClosedbooleanWhether the document has been closed

Methods

MethodReturnsDescription
.getPage(index)PDFPageGet a page (0-indexed)
.search(query, options?)SearchResult[]Full-text search across all pages
.getFormFields()Promise<FormFieldData[]>Read form fields (full tier)
.setFormField(name, value)Promise<void>Fill a form field (full tier)
.flattenForms(usage?)Promise<void>Flatten forms (full tier)
.getSignatures()Promise<SignatureData[]>Read signatures (full tier)
.save()Promise<Uint8Array>Save modified PDF (full tier)
.close()voidFree all WASM memory

PDFPage

Represents a single page. Access rendering, text, search, and annotations.

Properties

PropertyTypeDescription
.pageIndexnumber0-based page index
.widthnumberPage width in PDF points
.heightnumberPage height in PDF points

Methods

MethodReturnsDescription
.render(canvas, options?)Promise<void>Render to canvas
.renderToImageData(options?)Promise<ImageData>Render to ImageData
.getText()stringExtract plain text
.getTextSpans()TextSpan[]Text with positions
.getCharBoxes()CharBox[]Character-level bounding boxes
.createTextLayer(container)HTMLElementBuild selectable text overlay
.search(query, options?)SearchResult[]Search this page
.getLinks()LinkInfo[]Extract hyperlinks
.getAnnotations()Promise<AnnotationData[]>Read annotations (full tier)
.addAnnotation(options)Promise<void>Add annotation (full tier)
.removeAnnotation(index)Promise<void>Remove annotation (full tier)
.close()voidFree page resources

WasmLoader

Controls WASM lifecycle and caching.

MethodReturnsDescription
WasmLoader.load(options?)Promise<WasmModule>Load the WASM module
WasmLoader.isLoaded()booleanCheck if loaded
WasmLoader.reset()voidDestroy and reset
WasmLoader.clearCache()Promise<void>Clear IndexedDB cache
WasmLoader.enableMock()voidForce mock mode (testing)

PageRenderer

Static utility for common rendering tasks.

import { PageRenderer } from "pdfnova/lite";
MethodReturnsDescription
PageRenderer.renderThumbnail(page, canvas, maxWidth)Promise<void>Render a thumbnail
PageRenderer.fitWidthScale(page, width)numberCalculate fit-to-width scale

VirtualRenderer

Virtualized page rendering for large documents.

import { VirtualRenderer } from "pdfnova/lite";
MethodReturnsDescription
new VirtualRenderer(options)VirtualRendererCreate renderer
.setDocument(doc)Promise<void>Set the document to render
.scrollToPage(index)voidScroll to a page
.getCurrentPage()numberGet current visible page

WorkerPool

Multi-threaded rendering via Web Workers.

import { WorkerPool } from "pdfnova/lite";
MethodReturnsDescription
new WorkerPool(count)WorkerPoolCreate pool with N workers
.init(options)Promise<void>Initialize workers
.renderPages(indices, options)Promise<ImageData[]>Render pages in parallel
.destroy()voidTerminate all workers

Types

RenderOptions

interface RenderOptions {
scale?: number; // Default: 1
rotation?: 0 | 90 | 180 | 270; // Default: 0
background?: string; // Hex color, default: "#ffffff"
flags?: number; // RENDER_FLAG bitmask
}

PDFMetadata

interface PDFMetadata {
title: string;
author: string;
subject: string;
keywords: string;
creator: string;
producer: string;
creationDate: string;
modDate: string;
}

TextSpan

interface TextSpan {
text: string;
x: number;
y: number;
width: number;
height: number;
fontSize: number;
charIndex: number;
charCount: number;
}

CharBox

interface CharBox {
char: string;
charCode: number;
left: number;
right: number;
top: number;
bottom: number;
fontSize: number;
index: number;
}

SearchResult

interface SearchResult {
pageIndex: number;
matchIndex: number;
charIndex: number;
charCount: number;
rects: TextRect[];
text: string;
}

SearchOptions

interface SearchOptions {
caseSensitive?: boolean;
wholeWord?: boolean;
}

TextRect

interface TextRect {
left: number;
top: number;
right: number;
bottom: number;
}

OutlineItem

interface OutlineItem {
title: string;
pageIndex: number;
children: OutlineItem[];
}

LinkInfo

interface LinkInfo {
url: string;
rects: TextRect[];
pageIndex: number;
}

AnnotationData

interface AnnotationData {
index: number;
type: AnnotationType;
rect: AnnotationRect;
color?: AnnotationColor;
contents?: string;
author?: string;
modificationDate?: string;
attachmentPoints?: AttachmentPoint[];
}

FormFieldData

interface FormFieldData {
name: string;
type: FormFieldType;
value: string;
flags: number;
isChecked?: boolean;
pageIndex: number;
annotIndex: number;
}

SignatureData

interface SignatureData {
index: number;
contents: Uint8Array;
byteRange: number[];
subFilter: string;
reason: string;
signingTime: string;
docMDPPermission: number;
}

OpenOptions

interface OpenOptions {
password?: string;
headers?: Record<string, string>;
credentials?: RequestCredentials;
wasmUrl?: string;
worker?: boolean;
}

Enums

enum AnnotationType {
Text = 1, Link = 2, FreeText = 3, Line = 4, Square = 5,
Circle = 6, Polygon = 7, Polyline = 8, Highlight = 9,
Underline = 10, Squiggly = 11, StrikeOut = 12, Stamp = 13,
Caret = 14, Ink = 15, Popup = 16, FileAttachment = 17,
Widget = 20, Watermark = 24, Redact = 28,
}

enum FormFieldType {
Unknown = -1, PushButton = 0, CheckBox = 1, RadioButton = 2,
ComboBox = 3, ListBox = 4, TextField = 5, Signature = 6,
}