Getting an error while trying to import annotations via xml string

WebViewer Version: 10

Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos? No
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? No
Is your issue related to annotations? Yes

Please give a brief summary of your issue:
Getting error while trying to import annotations with await annotationManager.importAnnotations

Please describe your issue and provide steps to reproduce it:
While trying webviewer SDK, we are trying to export and import highlight annotation with XML String.
It works fine with simple highlight. However when we add comment to a highlight and then try to import exported xfdf string we are getting below error.

VM6102:1 Uncaught (in promise) SyntaxError: Expected ‘,’ or ‘}’ after property value in JSON at position 157
at JSON.parse ()
at z.wS (webviewer-core.min.js:2576:292)
at n (webviewer-core.min.js:2579:108)…

Usage is pretty simple.

const ymlString = <?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><pdf-info xmlns="http://www.pdftron.com/pdfinfo" version="2" import-version="4" /><fields /><annots><highlight page="2" rect="101.823,546.447,289.804,614.990" color="#FFCD45" flags="print" name="acdb94cb-47d1-70b6-5471-c0329260262b" title="Kapil" subject="Highlight" date="D:20230331170302+05'30'" creationdate="D:20230331170217+05'30'" coords="101.8356141564941,614.9903058593754,280.6261340864942,614.7917807493757,101.82287281494138,603.4943585937494,280.6133927449414,603.2958334837497,101.8385160564941,595.9942792593754,289.8041073864943,595.7855663493757,101.82577471494137,584.4983319937496,289.7913660449416,584.2896190837499,101.8414179564941,576.9982526593758,285.9010160964942,576.7938768793756,101.82867661494137,565.5023053937498,285.88827475494145,565.2979296137496,101.84431985649412,558.0022260593753,155.14717264649414,557.9430397293752,101.8315785149414,546.5062787937501,155.1344313049414,546.4470924637501"><trn-custom-data bytes="{&quot;trn-annot-preview&quot;:&quot;A first mistake organizations make when selecting a PDF library for the first time is to assume fixed feature requireme&quot;,&quot;trn-mention&quot;:&quot;{\&quot;contents\&quot;:\&quot;Some test comment\\n\\n\&quot;,\&quot;ids\&quot;:[]}&quot;,&quot;trn-attachments&quot;:&quot;[]&quot;}"/><contents>Some test comment</contents><contents-richtext><body><p><span>Some test comment</span></p></body></contents-richtext></highlight></annots><pages><defmtx matrix="1,0,0,-1,0,792" /></pages></xfdf>;

in component after loading the document and annotations we try to import above xfdf string (which was exported via the document itself)
documentViewer.addEventListener(‘annotationsLoaded’, async () => {

      const annotations = await annotationManager.importAnnotations(ymlString); // this is where error occurs
      
      annotations.forEach((annotation) => {
        console.log(annotation);
        annotationManager.redrawAnnotation(annotation);
      });
    });

I guess the problem is with below snippet in the xfdf.
<trn-custom-data bytes="{&quot;trn-annot-preview&quot;:&quot;A first mistake organizations make when selecting a PDF library for the first time is to assume fixed feature requireme&quot;,&quot;trn-mention&quot;:&quot;{\&quot;contents\&quot;:\&quot;Some test comment\\n\\n\&quot;,\&quot;ids\&quot;:[]}&quot;,&quot;trn-attachments&quot;:&quot;[]&quot;}"/>

I will take a look at this issue and see what’s going on.

Best,
Will

Thanks, Will. Looking forward to it.

Issue I think is with some Non ASCII characters generated in the output.

Could you copy paste the text you’re using in the reply?

Thanks!
Will

Hello Wil,
We are trying multiline comments in the above example. e.g.
Some test comment

(Two /n s here…)

Thanks,
Kapil

Still the same… just export annotation string and apply it back. It gives the error when there are some multiline replies.

tried below as well, didnt work.
data.replace(‘&quot;’,‘’)

Hi Kapil,

I was unable to reproduce this issue. Are you creating the annotations programmatically?

Best,
Will

Hello Will,

Just FYI. We have moved to converting xml xfdf string to json and saving it to the DB and it is working fine now. No issues.
(However,
I think the issue here was, we were logging the string to console and copying it from there. Due to this there were some characters introduced I guess which caused the problem. You can try to output to a console and copy xfdf string and try to import it as hardocded string. Normally this worked except when some comments are added. .i.e. trn-custom-data.)

Thanks for your support Will.

Thanks,
Kapil.