Skip to main content

The annotationId field

The Annotation table/entity contains two different IDs - id and annotationId.

The id field is the unique primary key generated by your database. The annotationId field is the ID given to the annotation by WebViewer. These values are stored separately in your database.

The annotations resolver requires that both properties be returned. However, many databases may not store the annotationId property.

Luckily, the annotationId can be parsed from the XFDF that is stored in your database.

The server exports a utility to do this:

import { parseAnnotationIdFromXFDF } from '@pdftron/collab-server'
const xfdf = `<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="" xml:space="preserve"><annots><square page="0" rect="102.11,385.56,376.7,635.37" color="#00CC63" flags="print" name="367ddbaf-02f3-ee5d-f1c7-ce9a6c43f5f2" title="Logan" subject="Rectangle" date="D:20210628130234-07'00'" creationdate="D:20210628130234-07'00'"/></annots></xfdf>`
const id = parseAnnotationIdFromXFDF(xfdf) // 367ddbaf-02f3-ee5d-f1c7-ce9a6c43f5f2

This utility can be used to write a migration script to add the annotationId column to your database.

Note: This is a very rough example

// migrate.js
import { parseAnnotationIdFromXFDF } from '@pdftron/collab-server'
const rows = await sqlClient('SELECT * FROM annotations')
rows.forEach((row) => {
const annotationId = parseAnnotationIdFromXFDF(row.xfdf);
await sqlClient(`UPDATE annotations SET annotation_id = ${annotationId} WHERE id = ${}`)