Merge XFDF string

Product: @pdftron/pdfnet-node

Product Version: 10.4.0

Please give a brief summary of your issue:
We’re using pdfnet-node sdk to generate different type of annotations, they are running on Google Cloud function and are independent from each other. One of them are:

  1. PDF location at top right (A0, B1, etc)
  2. Text annotation at bottom right of each page

When I call await doc.mergeXFDFString(this.xfdf); it’s gonna throw duplicate annotation error and I have to set merge option setForce(true)

const mergeOptions = new PDFNet.PDFDoc.MergeXFDFOptions();
mergeOptions.setForce(true);

await doc.mergeXFDFString(xfdf, mergeOptions);

I find duplicate name for this one. 55deac590367400a-13b5a19c48e7aa52 and it is not showing on webviewer.

How can I ensure the annotation is unique? so that mergeXFDFString works seamlessly?

Here are my code and xfdf file
446.xml (11.5 KB)
location.pdf.ts (2.3 KB)
reviewed.pdf.ts (2.0 KB)

1 Like

Thank you for contacting Apryse support.

I’m reviewing your request and will get back to you shortly.

1 Like

Thanks for the example code. I will get this over to the appropriate team. They should be in contact shortly.

1 Like

It is against the PDF specification to have two annotations on the same page with the same ID. That is, annotation IDs are unique in the page scope.

In your 446.xml you have two annotations on the same page with same ID, so your XFDF is already in a bad state.

Since this particular ID is a GUID it is not possible to have a collision randomly, so somehow the annotation was duplicated, on the same page, without updating the ID.

You would need to review how/when you are creating these annotations to determine what exact step is resulting in the duplicate annotation. For instance, exporting XFDF at each step to determine precisely what API call is causing it.

1 Like

If it’s a GUID then it shouldn’t have duplicate, here is my typical workflow:

  1. Generate document position annotation with location.pdf.ts , store the XFDF in the system storage.
  2. Pass existing XFDF to reviewed.pdf.ts and generate document reviewed stamp at the bottom of the document.

How come these have different date but still have the same GUID? cedc275bf127f6b0-8ef9257c48d351b5
image

Can I use setUniqueID? and how to use it? since it accepts ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray

xfdf.xml (7.2 KB)

1 Like

Yes you can use setUniqueID, there should be a means to create a GUID using your current language/framework. From there you should be able to find a way to convert that returned object to one that is accepted by setUniqueID.

2 Likes