Annotations and measurements
Let users annotate, comment on and measure PDFs in an Electron window with NexPDF, and choose the tools, colours and stamps they get.
License module
Creating and changing annotations and measurements needs the annotations module (Indie tier and
above). Showing annotations works without a key.
The Annotate mode
The Annotate mode (annotations) has these tools, each with its id in the configuration:
| Tools | Ids |
|---|---|
| Note | note |
| Pen, highlighter pen, eraser | ink, inkHighlight, eraser |
| Highlight, underline, strikethrough, squiggly | highlight, underline, strikeout, squiggly |
| Rectangle, ellipse, arc, polygon, cloud, polyline, line, arrow | square, circle, arc, polygon, cloud, polyline, line, arrow |
| Text box, callout, stamp, signature, image stamp, link | freetext, callout, stamp, signature, image, link |
The comments tab of the side panel lists the document's comments.
Choose the tools, colours and stamps
const fs = require('node:fs');
const path = require('node:path');
const config = path.join(app.getPath('userData'), 'nexpdf-ui.json');
fs.writeFileSync(config, JSON.stringify({
modeConfig: { initialMode: 'annotations', availableModes: ['viewer', 'annotations'] },
annotationsConfig: {
availableTools: ['note', 'ink', 'highlight', 'underline', 'square', 'arrow', 'freetext', 'stamp'],
defaultColor: '#2557D6',
colorPalette: ['#2557D6', '#E5372B', '#2FB344', '#1D1B18'],
presets: { ink: { color: '#1D4ED8', width: 3 }, highlight: { color: '#FDE047', opacity: 0.35 } },
stamps: ['APPROVED', 'REJECTED', 'DRAFT'],
},
collaboration: { userName: 'Ana Silva' },
}));
await openPdfWindow({ file, config });| Key | What it does |
|---|---|
annotationsConfig.availableTools | The tools to offer, in this order |
annotationsConfig.defaultColor / defaultOpacity | The colour (#RRGGBB or #RRGGBBAA) and opacity (0.05 to 1) new annotations start with |
annotationsConfig.colorPalette | The swatches in the style picker |
annotationsConfig.presets | The style each tool starts with: color, opacity, width, fontSize |
annotationsConfig.rememberStyles | Each tool starts with the last style picked on this machine (default true) |
annotationsConfig.stamps | The texts the stamp tool offers, at most 40 characters each |
annotationsConfig.defaultFontSize | The font size of text boxes |
collaboration.userName | The name shown on comments |
The Measure mode
The Measure mode (measurement) measures distances, perimeters and areas on the page and saves
them in the PDF with Save in PDF. Include measurement in modeConfig.availableModes to offer
it.
Keep the annotated file
pdf.save(path) writes the document with every annotation, and pdf.bytes() returns it as a
Buffer. To annotate in code, use the document API
(openDocumentFile, then the calls of the Node.js SDK).