Instant JSON format for PDF annotations explained

This guide explains how to format JSON when you work with Instant annotations.

Types

This section explains how to use type declarations in Instant JSON records.

The optional keys are specified as follows:

{ optionalKey?: value; }

To reduce payload size, omit optional keys when their values are undefined.

Throughout this guide, the JSON tab shows an example of the format. Switch to the JavaScript tab to see complete type declarations, which document is each key’s expected type, whether the key is optional, and how the value is expected to be used.

Annotation types

The following annotation types are supported:

  • pspdfkit/image
  • pspdfkit/ink
  • pspdfkit/link
  • pspdfkit/markup/highlight
  • pspdfkit/markup/redaction
  • pspdfkit/markup/squiggly
  • pspdfkit/markup/strikeout
  • pspdfkit/markup/underline
  • pspdfkit/note
  • pspdfkit/comment-marker
  • pspdfkit/shape/ellipse
  • pspdfkit/shape/line
  • pspdfkit/shape/polygon
  • pspdfkit/shape/polyline
  • pspdfkit/shape/rectangle
  • pspdfkit/stamp
  • pspdfkit/text

Basic properties

Annotations can include many different properties, some of them shared among several annotation types. These properties are serialized in Instant JSON following the rules described in this guide.

Basic types

We define a number of low-level types that are used throughout all annotation types.

Geometry

Geometry always represents points inside a page. The coordinate space origin is the top-left corner of the page, with the x-axis increasing to the right, and the y-axis increasing downward. Rectangles are positioned at their top-left point:

// Examples of payloads for geometry data types:
// Rect
[100, 150, 200, 150][
// Point
(120, 50)
][
// CloudyBorderInset
(10, 10, 10, 10)
]

Other

// Example of Instant JSON values:
// Color
"#ffcc00"
// Lines
{
"intensities": [
[0.5, 0.5, 0.5]
],
"points": [
[100, 120], [110, 121], [120, 122]
]
}
// LineCaps
{
"start": "openArrow",
"end": "square"
}

Action types

Refer to the JSON format schema — actions guide.

Base annotation type

Every annotation shares a set of common values, which are formalized in the BaseAnnotation type. Later in this guide, you’ll see all annotations extend this type using type intersection(opens in a new tab).

This means that a specific annotation needs to have all the properties of BaseAnnotation and all the properties of its specific annotation type:

// Example of an Instant JSON schema for `BaseAnnotation`:
{
"v": 1,
"pageIndex": 0,
"bbox": [150, 75, 120, 70],
"opacity": 1,
"pdfObjectId": 100,
"flags": ["noZoom", "noRotate"],
"creatorName": "John Doe",
"createdAt": "2012-04-23T18:25:43.511Z",
"updatedAt": "2012-04-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F83",
"name": "01F46S31WM8Q46MP3T0BAJ0F83"
}

pspdfkit/markup/{highlight, squiggly, strikeout, underline}

Markup annotations include highlight, squiggly, strikeout, and underline. All of these require a list of rectangles that they’re drawn to. The highlight annotation will lay the color on top of the element and apply the multiply blend mode.

Markup annotations

// Example of an Instant JSON schema for a markup annotation:
{
"v": 1,
"pageIndex": 1,
"bbox": [150, 275, 120, 70],
"opacity": 1,
"pdfObjectId": 200,
"creatorName": "John Doe",
"createdAt": "2012-04-23T18:25:43.511Z",
"updatedAt": "2012-04-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F84",
"name": "01F46S31WM8Q46MP3T0BAJ0F84",
"type": "pspdfkit/markup/highlight",
"rects": [[150, 275, 120, 70]],
"blendMode": "multiply",
"color": "#ffff00"
}

pspdfkit/markup/redaction

Redaction annotations are markup annotations, but they support some additional properties, so we have a specific type for them.

You have to have licensed the Redaction component to use redaction annotations.

// Example of an Instant JSON schema for a markup annotation:
{
"v": 1,
"pageIndex": 1,
"bbox": [150, 275, 120, 70],
"opacity": 1,
"pdfObjectId": 200,
"creatorName": "John Doe",
"createdAt": "2012-04-23T18:25:43.511Z",
"updatedAt": "2012-04-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F84",
"name": "01F46S31WM8Q46MP3T0BAJ0F84",
"type": "pspdfkit/markup/redaction",
"outlineColor": "#ff0000",
"fillColor": "#000000",
"overlayText": "REDACTED",
"repeatOverlayText": true,
"rotation": 0
}

With redaction annotations, the rects property determines the location of the area marked for redaction.

pspdfkit/text

A text annotation can be placed anywhere on the screen. Keep in mind that fonts are client specific, so you should only use fonts you know are present in the browser where they should be displayed. If a font isn’t found, Nutrient will automatically fall back to a sans-serif font.

Text annotations
// Example of an Instant JSON schema for a text annotation:
{
"v": 1,
"pageIndex": 1,
"bbox": [150, 275, 120, 70],
"opacity": 1,
"pdfObjectId": 200,
"creatorName": "John Doe",
"createdAt": "2012-04-23T18:25:43.511Z",
"updatedAt": "2012-04-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F85",
"name": "01F46S31WM8Q46MP3T0BAJ0F85",
"type": "pspdfkit/text",
"text": "Content for a text annotation",
"fontSize": 14,
"fontStyle": ["bold"],
"fontColor": "#000000",
"horizontalAlign": "left",
"verticalAlign": "center",
"rotation": 0
}

pspdfkit/ink

Ink annotations are used for freehand drawings on a page. They can contain multiple segments (see the definition of Lines above). Points within a segment are connected to a line.

Ink annotations
// Example of an Instant JSON schema for an ink annotation:
{
"v": 1,
"pageIndex": 2,
"bbox": [95, 115, 125, 127],
"opacity": 1,
"pdfObjectId": 250,
"creatorName": "John Doe",
"createdAt": "2012-04-23T18:05:43.511Z",
"updatedAt": "2012-04-23T18:08:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F85",
"name": "01F46S31WM8Q46MP3T0BAJ0F85",
"type": "pspdfkit/ink",
"lines": {
"intensities": [[0.5, 0.5, 0.5]],
"points": [
[
[100, 120],
[110, 121],
[120, 122]
]
]
},
"lineWidth": 10,
"isDrawnNaturally": false,
"strokeColor": "#8080ff"
}

A link can be used to trigger an action when clicked or pressed. The link will be drawn on the bounding box.

Link annotations
// Example of an Instant JSON schema for a link annotation:
{
"v": 1,
"pageIndex": 1,
"bbox": [95, 115, 125, 127],
"opacity": 1,
"pdfObjectId": 200,
"creatorName": "John Doe",
"createdAt": "2012-04-23T18:25:43.511Z",
"updatedAt": "2012-04-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F86",
"name": "01F46S31WM8Q46MP3T0BAJ0F86",
"type": "pspdfkit/link",
"action": {
"type": "goTo",
"pageIndex": 10
},
"note": "Text note for the annotation"
}

pspdfkit/note

Note annotations are “sticky notes” attached to a point in the PDF document. They’re represented as markers, and each one has an icon associated with it. Its text content is revealed on selection.

Note annotations
// Example of an Instant JSON schema for a note annotation:
{
"v": 1,
"pageIndex": 1,
"bbox": [95, 115, 125, 127],
"opacity": 1,
"pdfObjectId": 200,
"creatorName": "John Doe",
"createdAt": "2012-04-23T18:25:43.511Z",
"updatedAt": "2012-04-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F87",
"name": "01F46S31WM8Q46MP3T0BAJ0F87",
"type": "pspdfkit/note",
"text": "Text for the note annotation",
"icon": "circle",
"color": "#80ff80"
}

pspdfkit/comment-marker

Refer to the JSON format schema — comments guide.

Shape annotations

Shape annotations are used to draw different shapes — lines, rectangles, ellipses, polylines, and polygons — on a page.

Shape annotations with a transparent fill color are only selectable around their visible lines. This means you can create a page full of shape annotations while annotations behind these shape annotations are still selectable:

// Example of a generic Instant JSON payload for shape annotations:
{
"v": 1,
"pageIndex": 0,
"bbox": [195, 215, 325, 427],
"opacity": 0.7,
"pdfObjectId": 300,
"creatorName": "John Doe",
"createdAt": "2012-05-23T18:25:43.511Z",
"updatedAt": "2012-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F88",
"name": "01F46S31WM8Q46MP3T0BAJ0F88",
// "type": "pspdfkit/shape/{line, rectangle, ellipse, polyline, polygon}",
"strokeDashArray": [3, 3],
"strokeWidth": 5,
"strokeColor": "#000000"
}

pspdfkit/shape/ellipse

Ellipse annotations are used to draw ellipses on a page.

Ellipse shape annotations
// Example of an Instant JSON schema for an ellipse annotation:
{
"v": 1,
"pageIndex": 0,
"bbox": [195, 215, 325, 427],
"opacity": 1,
"pdfObjectId": 120,
"creatorName": "John Doe",
"createdAt": "2012-05-23T18:25:43.511Z",
"updatedAt": "2012-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F89",
"name": "01F46S31WM8Q46MP3T0BAJ0F89",
"type": "pspdfkit/shape/ellipse",
"strokeWidth": 5,
"strokeColor": "#0000ff",
"fillColor": "#ffffff",
"cloudyBorderIntensity": 1,
"cloudyBorderInset": [10, 10, 10, 10]
}

pspdfkit/shape/rectangle

Rectangle annotations are used to draw rectangles on a page.

Rectangle shape annotations
// Example of an Instant JSON schema for a rectangle:
{
"v": 1,
"pageIndex": 0,
"bbox": [195, 215, 325, 427],
"opacity": 1,
"pdfObjectId": 120,
"creatorName": "John Doe",
"createdAt": "2012-05-23T18:25:43.511Z",
"updatedAt": "2012-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F8A",
"name": "01F46S31WM8Q46MP3T0BAJ0F8A",
"type": "pspdfkit/shape/rectangle",
"strokeWidth": 5,
"strokeColor": "#0000ff",
"fillColor": "#ffffff"
}

pspdfkit/shape/line

Line annotations are used to draw straight lines on a page.

Line shape annotations
// Example of an Instant JSON schema for a line annotation:
{
"v": 1,
"pageIndex": 0,
"bbox": [195, 215, 325, 427],
"opacity": 1,
"pdfObjectId": 120,
"creatorName": "John Doe",
"createdAt": "2012-05-23T18:25:43.511Z",
"updatedAt": "2012-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F8B",
"name": "01F46S31WM8Q46MP3T0BAJ0F8B",
"strokeWidth": 5,
"strokeColor": "#0000ff",
"fillColor": "#ffffff",
"type": "pspdfkit/shape/line",
"startPoint": [40, 60],
"endPoint": [100, 200],
"lineCaps": {
"start": "openArrow"
}
}

pspdfkit/shape/polyline

Polyline annotations are used to draw polylines on a page by hand. They can contain any number of sides, which are defined by the polyline vertices.

Polyline shape annotations
// Example of an Instant JSON schema for a polyline annotation:
{
"v": 1,
"pageIndex": 5,
"bbox": [15, 25, 90, 60],
"opacity": 1,
"pdfObjectId": 220,
"creatorName": "John Doe",
"createdAt": "2012-05-23T18:25:43.511Z",
"updatedAt": "2012-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F8C",
"name": "01F46S31WM8Q46MP3T0BAJ0F8C",
"strokeWidth": 10,
"strokeColor": "#0000ff",
"fillColor": "#ffffff",
"type": "pspdfkit/shape/polyline",
"fillColor": "#ff0000",
"lineCaps": {
"start": "circle",
"end": "circle"
},
"points": [
[20, 30],
[100, 70],
[55, 80]
]
}

pspdfkit/shape/polygon

Polygon annotations are used to draw polygons on a page by hand. They can contain any number of sides, which are defined by the polygon vertices.

Polygon shape annotations
// Example of an Instant JSON schema for a polygon annotation:
{
"v": 1,
"pageIndex": 3,
"bbox": [15, 25, 90, 60],
"opacity": 1,
"pdfObjectId": 230,
"creatorName": "John Doe",
"createdAt": "2012-05-23T18:25:43.511Z",
"updatedAt": "2012-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F8D",
"name": "01F46S31WM8Q46MP3T0BAJ0F8D",
"strokeWidth": 10,
"strokeColor": "#0000ff",
"type": "pspdfkit/shape/polygon",
"points": [
[20, 30],
[100, 70],
[55, 80]
]
}

pspdfkit/image

Image annotations are used to annotate a PDF with images.

Image annotation
// Example of an Instant JSON schema for an image annotation:
{
"v": 1,
"pageIndex": 3,
"bbox": [15, 25, 90, 60],
"opacity": 1,
"pdfObjectId": 230,
"creatorName": "John Doe",
"createdAt": "2020-05-23T18:25:43.511Z",
"updatedAt": "2020-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F8E",
"name": "01F46S31WM8Q46MP3T0BAJ0F8E",
"type": "pspdfkit/image",
"description": "Company logo",
"contentType": "image/jpeg",
"imageAttachmentId": "800",
"rotation": 0
}

For more information on attachments, refer to the JSON format schema — file attachments guide.

pspdfkit/stamp

A stamp annotation represents a stamp in a PDF. The image of the stamp depends upon the stampType, which can be one of the following:

  • Accepted
  • Approved
  • AsIs
  • Completed
  • Confidential
  • Departmental
  • Draft
  • Experimental
  • Expired
  • Final
  • ForComment
  • ForPublicRelease
  • InformationOnly
  • InitialHere
  • NotApproved
  • NotForPublicRelease
  • PreliminaryResults
  • Rejected
  • Revised
  • SignHere
  • Sold
  • TopSecret
  • Void
  • Witness
  • Custom

If the stampType is set to Custom, the title, subtitle, and color will define the appearance of the stamp annotation.

Stamp Annotations
// Example of an Instant JSON schema for a stamp annotation:
{
"v": 1,
"pageIndex": 0,
"bbox": [150, 250, 150, 100],
"opacity": 1,
"pdfObjectId": 300,
"creatorName": "John Doe",
"createdAt": "2020-05-23T18:25:43.511Z",
"updatedAt": "2020-06-23T18:28:05.100Z",
"id": "01F46S31WM8Q46MP3T0BAJ0F8F",
"name": "01F46S31WM8Q46MP3T0BAJ0F8F",
"type": "pspdfkit/stamp",
"stampType": "Approved",
"title": "Approved",
"color": "#00ff00",
"rotation": 0
}