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:
| Parameter | Type | Description |
|---|---|---|
source | string | ArrayBuffer | Uint8Array | File | Blob | PDF source — URL, buffer, File, Blob, or base64 data URI |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
password | string | — | Password for encrypted PDFs |
headers | Record<string, string> | — | HTTP headers for URL fetching |
credentials | RequestCredentials | — | Fetch credentials mode |
wasmUrl | string | jsDelivr CDN | Custom WASM binary URL |
Returns: Promise<PDFDocument>
Properties
| Property | Type | Description |
|---|---|---|
.pageCount | number | Total number of pages |
.metadata | PDFMetadata | Document metadata (title, author, etc.) |
.outline | OutlineItem[] | Bookmark/TOC tree |
.permissions | PDFPermissions | Document permissions |
.isClosed | boolean | Whether the document has been closed |
Methods
| Method | Returns | Description |
|---|---|---|
.getPage(index) | PDFPage | Get 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() | void | Free all WASM memory |
PDFPage
Represents a single page. Access rendering, text, search, and annotations.
Properties
| Property | Type | Description |
|---|---|---|
.pageIndex | number | 0-based page index |
.width | number | Page width in PDF points |
.height | number | Page height in PDF points |
Methods
| Method | Returns | Description |
|---|---|---|
.render(canvas, options?) | Promise<void> | Render to canvas |
.renderToImageData(options?) | Promise<ImageData> | Render to ImageData |
.getText() | string | Extract plain text |
.getTextSpans() | TextSpan[] | Text with positions |
.getCharBoxes() | CharBox[] | Character-level bounding boxes |
.createTextLayer(container) | HTMLElement | Build 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() | void | Free page resources |
WasmLoader
Controls WASM lifecycle and caching.
| Method | Returns | Description |
|---|---|---|
WasmLoader.load(options?) | Promise<WasmModule> | Load the WASM module |
WasmLoader.isLoaded() | boolean | Check if loaded |
WasmLoader.reset() | void | Destroy and reset |
WasmLoader.clearCache() | Promise<void> | Clear IndexedDB cache |
WasmLoader.enableMock() | void | Force mock mode (testing) |
PageRenderer
Static utility for common rendering tasks.
import { PageRenderer } from "pdfnova/lite";
| Method | Returns | Description |
|---|---|---|
PageRenderer.renderThumbnail(page, canvas, maxWidth) | Promise<void> | Render a thumbnail |
PageRenderer.fitWidthScale(page, width) | number | Calculate fit-to-width scale |
VirtualRenderer
Virtualized page rendering for large documents.
import { VirtualRenderer } from "pdfnova/lite";
| Method | Returns | Description |
|---|---|---|
new VirtualRenderer(options) | VirtualRenderer | Create renderer |
.setDocument(doc) | Promise<void> | Set the document to render |
.scrollToPage(index) | void | Scroll to a page |
.getCurrentPage() | number | Get current visible page |
WorkerPool
Multi-threaded rendering via Web Workers.
import { WorkerPool } from "pdfnova/lite";
| Method | Returns | Description |
|---|---|---|
new WorkerPool(count) | WorkerPool | Create pool with N workers |
.init(options) | Promise<void> | Initialize workers |
.renderPages(indices, options) | Promise<ImageData[]> | Render pages in parallel |
.destroy() | void | Terminate 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,
}