Import PDF Annotations in Node.js

You can annotate PDFs with Node.js by importing them into an input file and including an Instant JSON file that contains annotations when initializing an instance via the load function.

Before you get started, make sure PSPDFKit for Node.js is up and running.

You can download these sample files to use as you work through the examples in this guide:

Applying Instant JSON to a Document

import fs from 'node:fs';
import { load } from '@pspdfkit/nodejs';

const pdfDoc = fs.readFileSync('source.pdf');
const myInstantJSON = JSON.parse(
	fs.readFileSync('instantjson.json', 'utf-8'),
);

const instance = await load({
	document: pdfDoc,
	instantJSON: myInstantJSON,
});
const buffer = await instance.exportPDF();

fs.writeFileSync('output.pdf', Buffer.from(buffer));
await instance.close();