Unable to retrieve the uniqueID of an annotation when converted from Core.Annotations.Annotation to PDFNet.Annot

WebViewer Version: 10.9.0

Do you have an issue with a specific file(s)? Sample code
Can you reproduce using one of our samples or online demos? Yes
Are you using the WebViewer server? No

Hello,

We are continuing to evaluate the WebViewer SDK and have a question with regards to retrieving an annotation’s unique ID. There appear to be two types of annotations: Core.Annotations.Annotation and PDFNet.Annot.

Here is what I am trying to do:

  1. get the list of selected annotations
  2. add them to an OCG layer

Here is what I have tried:

  1. get list of selected annotations:
    I have hooked into the appropriate event to call annotationManager.getSelectedAnnotations(). This returns an array of Core.Annotations.Annotation and each one of these contains an Id.

  2. add them to OCG layer:
    I am using PDFNet.OCG to create this layer like so: let ocgLayer = await PDFNet.OCG.create(pdfDoc, 'layerName'); but then I realized after looking at a few samples, that I have to convert from Core.Annotations.Annotation to PDFNet.Annot to be able to associate the annotation with the ocf layer.

So what I am doing is get the XFDF representation of the selected annotations using:
let xfdfAnnotations = await annotationManager.exportAnnotations({annotationList: selectedAnnotations});

Then I attempt to import them into the underlying PDF doc as follows:

    let pdfDoc = await documentViewer.getDocument().getPDFDoc();
 await pdfDoc.mergeXFDFString(xfdfAnnotations, new PDFNet.PDFDoc.MergeXFDFOptions().setForce(false));

Next, I iterate through the pages of the above pdfDoc and use page.getAnnots(pageNumber) to get an instance of each PDFNet.Annot.

For each instance, when I call await annot.getUniqueID() I get null, even though the exported XFDF has a name attribute.

What am I missing? The sample XFDF is below:

<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><annots><square page="1" rect="100,592,300,642" color="#000000" flags="print" name="66f150fb-31eb-9c5f-c4e1-4a0b14cbdc4f" title="Guest" subject="Rectangle" date="D:20241013090528-05'00'" creationdate="D:20241013090528-05'00'"/></annots></xfdf>

Hi there,

On WebViewer, you can use 2 types of annotations:

  • instance.Core.PDFNet.Annot
  • instance.Core.Annotations.Annotation

PDFNet.Annot is part of the full API that is generally used to work with server side operations.
Annotations.Annotation is the class within the WebViewer’s client-side JavaScript library, which is used to create and manipulate annotations in the browser.

An example of converting a WebViewer object to PDFNet object can be seen here:

You will need to extract the annotation properties and instantiate a new instance of the PDFNet’s annot object.
You can see the required properties for SquareAnnot here:
https://docs.apryse.com/api/web/Core.PDFNet.SquareAnnot.html#main
And the WebViewer’s rectangle annotation:
https://docs.apryse.com/api/web/Core.Annotations.RectangleAnnotation.html#main

Best regards,
Kevin Kim