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:
- get the list of selected annotations
- add them to an OCG layer
Here is what I have tried:
-
get list of selected annotations:
I have hooked into the appropriate event to callannotationManager.getSelectedAnnotations()
. This returns an array ofCore.Annotations.Annotation
and each one of these contains an Id. -
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 fromCore.Annotations.Annotation
toPDFNet.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>