Docs / Guides

Markdown

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

FieldMeaning
typeOne of the types above
rect[x0, y0, x1, y1] for boxes; worked out for you for lines and shapes
quadPointsText 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
verticesPolygon and polyline points
color, fillColor, textColor#rrggbb; fillColor: null means no fill
opacity, borderWidth, borderStyle, dash0 to 1, points, solid / dashed / cloudy, [on, off]
contents, author, subjectText
fontSize, font, align, rotationText boxes: size, Helvetica / Times / Courier, alignment, 0 / 90 / 180 / 270
bold, italic, underline, strikeout, valign, autoFitText-box lettering, vertical alignment, shrink to fit
uri, destPageLinks
hidden, lockedFlags
inReplyTo, replyTypeReplies (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.