Clarification on Exporting and Importing Annotations in PDF.js Express Plus: API Usage and Limits

Which product are you using?

PDF.js Express Plus

PDF.js Express Version

8.7.2

Detailed description of issue

I am using PDF.js Express Plus version 8.7.2 with the annotation feature enabled. My goal is to:

  1. Save annotations drawn on the viewer to a database.
  2. Load annotations back into the document from the database when revisiting the document.

I am using the following code for importing and exporting annotations:

Loading Annotations from Database:

javascript

Copy code

// After the document is loaded, we load the annotations from the database
instance.Core.documentViewer.addEventListener('documentLoaded', async () => {
  const xfdfString = await loadXFDF(docId);
  await instance.Core.annotationManager.importAnnotations(xfdfString);
});

Saving Annotations to Database:

javascript

Copy code

// When the "save" button is clicked, we export 
// the annotations and save them to the database
saveButton.onclick = async () => {
  const xfdfString = await instance.Core.annotationManager.exportAnnotations();
  await saveToDatabase(docId, xfdfString);
};

Questions:

  1. Are exportAnnotations and importAnnotations API-dependent calls, or are they strictly handled on the client side?
    Specifically, do they require API usage credits, or are they independent of API limits?
  2. Is there a limit on the size or complexity of annotations when using exportAnnotations and importAnnotations?
    Will exporting a large number of annotations or importing a large XFDF string impact the viewer’s performance or cause any issues?
  3. Are there any recommended best practices for handling large XFDF strings when saving to and loading from the database?

Expected behaviour

  • The annotations should export as an XFDF string without any API limitations or size restrictions and should load back correctly into the viewer without performance degradation.

Does your issue happen with every document, or just one?

This is a general question, applicable to any document.

Link to document

N/A

Code snippet

Provided above.

Hi there,

  1. Are exportAnnotations and importAnnotations API-dependent calls, or are they strictly handled on the client side?
    Specifically, do they require API usage credits, or are they independent of API limits?

This is handled on the client side and does not use API usage credits.

  1. Is there a limit on the size or complexity of annotations when using exportAnnotations and importAnnotations?
    Will exporting a large number of annotations or importing a large XFDF string impact the viewer’s performance or cause any issues?

This will depend on the annotation size and the number of annotations. You can test various documents on our demo page to get a general idea of the performance speed:

You might want to also consider Apryse WebViewer as an alternative if performance is important for you:

  1. Are there any recommended best practices for handling large XFDF strings when saving to and loading from the database?

What you have above is generally the recommend way:

However, if there are large amounts of annotations, you may want to parse them partially at a time. You can break down the number of annotations and import them slowly instead of all at once.

Best regards,
Kevin

Thanks Kevin for the support and prompt response