Annotations
Create, read, change and remove annotations from code. They are standard PDF annotations with their own appearance, so they look the same in other PDF readers.
Create and change
app.js
const id = doc.addAnnotation(0, { type: 'Square', rect: [72, 600, 272, 700], color: '#ff0000' });doc.updateAnnotation(id, { contents: 'Please review', opacity: 0.8 });doc.annotations(0); // every annotation on page 1doc.deleteAnnotation(id);Types
Highlight, Underline, StrikeOut, Squiggly, Text (sticky note), FreeText, Square, Circle, Line, Arrow, Polygon, PolyLine, Ink, Stamp, Link, Caret, Redact.
Fields
| Field | Meaning |
|---|---|
type | One of the types above |
rect | [x0, y0, x1, y1] for boxes; worked out for you for lines and shapes |
quadPoints | Text markup: 8 numbers per line of text (upper left, upper right, lower left, lower right) |
inkList | [[x, y, x, y, …], …] free-hand strokes |
line, lineEndings | [x1, y1, x2, y2]; endings None, OpenArrow, ClosedArrow, Circle, Square, Diamond, Butt, Slash, ROpenArrow, RClosedArrow |
vertices | Polygon and polyline points |
color, fillColor, textColor | #rrggbb; fillColor: null means no fill |
opacity, borderWidth, borderStyle, dash | 0 to 1, points, solid / dashed / cloudy, [on, off] |
contents, author, subject | Text |
fontSize, font, align, rotation | Text boxes: size, Helvetica / Times / Courier, alignment, 0 / 90 / 180 / 270 |
bold, italic, underline, strikeout, valign, autoFit | Text-box lettering, vertical alignment, shrink to fit |
uri, destPage | Links |
hidden, locked | Flags |
inReplyTo, replyType | Replies (R) and grouped marks (Group) |
Returned only: id, page, subtype, created, modified, hasAppearance, popup.
Highlight search results
for (const hit of doc.search('net 30')) { doc.addAnnotation(hit.page, { type: 'Highlight', quadPoints: hit.quadPoints, contents: 'Payment terms' });}Store them yourself
exportAnnotations() returns every annotation as JSON and importAnnotations(list) puts them back: keep reviews in your own database and show them on a clean file later. flatten() draws annotations into the page content for good.