Skip to main content

External annotation syncing

info

This feature requires the userByIdentifier resolver to be set.

If you are using the default database or the SQL resolver generator, this is already set for you.

The Document.syncAnnotations API can be used to sync annotations that were created or edited outside of your application with your database.

This is useful in the case where your user downloads a document, annotates it offline (outside of the context of your application) and then re-uploads the document.

Document.syncAnnotations(file): Promise<{ added: string[], updated: string[] }>

Syncs a documents annotations with the database.

  • file (Blob | File | URL) The document to sync

Returns an object with 'added' and 'updated' properties. Each property contains an array of annotation IDs that were added or updated from the sync operation.

Example

[](../../../collab-server/src/util)import { CollabClient } from '@pdftron/collab-client'
const client = new CollabClient({...options})
const user = await client.loginAnonymously('Joe');
const document = await user.getDocument('abc');
const { added, updated } = await document.syncAnnotations('https://mywebsite.com/path/to/document')
console.log(`Added ${added.length} annotations and updated ${updated.length} annotations`);

How annotation syncing works#

The follow operations are executed:

  • Any annotations that exist in the new document but not in the database are added.
    • If the author of the new annotation can not be found or cannot be determined, the author becomes the current user. However, this can be configured (see documentation here)
  • If an annotation exists in both the database and the new document, then the annotation is edited if:
    • The updatedAt property on the new annotation is more recent than the updatedAt in the database
note

If the ID of an incoming annotation cannot be determined, it is ignored and not synced.