PdfCanvas
IT

Core API

The engine exposes a small surface: load a document, place objects, manage pages, undo, and export. Everything is synchronous except loading, image insertion and export.

Open the PDF editorLast updated:

Constructor options

OptionDefaultPurpose
workerSrc— (required)PDF.js worker URL
cMapUrl—CMaps directory
standardFontDataUrl—Standard fonts directory
wasmUrl—PDF.js WASM decoders
pdfiumWasmUrl—Enables editing original text
fontAssetsUrl—Bundled fallback fonts
initialZoom1Number, fit-width or fit-page
minZoom / maxZoom0.15 / 5Zoom limits
historyLimit60Undo steps in memory
maxFileSize200 MBMaximum accepted file
accent#6b4effSelection colour
onError—Non-fatal error hook

Load, export, inspect

await pdf.load(source, { fileName: "contract.pdf" });
const bytes = await pdf.exportPdf({ fileName: "contract.pdf" });
await pdf.download();

pdf.getState();     // serialisable snapshot
pdf.getPages();     // id, index, width, height, rotation, objectCount
await pdf.getThumbnails(140);

Objects

pdf.addText(80, 120, { text: "Hello", fontSize: 24, color: "#6b4eff" });
await pdf.addImage(dataUrl, { x: 40, y: 40, width: 200 });
await pdf.addImageFile(file);
await pdf.addSignature(pngDataUrl);
pdf.addShape("rect", { x: 80, y: 180, width: 200, height: 90 });

pdf.updateSelected({ color: "#ff5b4a", fontSize: 28 });
pdf.duplicateSelected();
pdf.deleteSelected();
pdf.bringForward();

Pages and history

await pdf.addBlankPage(2);
pdf.duplicatePage(0);
pdf.deletePage(1);
pdf.rotatePage(0, 90);
pdf.movePage(3, 0);
pdf.goToPage(2);

pdf.undo();
pdf.redo();

Original text and tools

pdf.setTool("text-edit");
pdf.on("originaledit", ({ edit }) => {
  if (edit) pdf.updateOriginalText({ boldOverride: true });
});

pdf.setZoom(1.25);
pdf.fitWidth();
pdf.fitPage();

Tools: select, text, text-edit, image, rect, ellipse, line, pen, highlight, whiteout. Whiteout covers content visually; it is not redaction.

Frequently asked questions

+Is the API stable?

The package is at 0.8.x. The model is usable, but minor versions may still change method signatures. Pin an exact version in production.

+How do I persist work?

getState() returns a serialisable snapshot. The editor entry adds IndexedDB autosave on top of it.

+Can I listen to selection changes?

Yes, through the event emitter: selection, page, zoom and original-text edit events. Check the types shipped with the package for the exact payloads.

Related pages