Importing annotation issue

const dataB = `<?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><text page="0" rect="791.040,2697.680,822.040,2728.680" color="#E44234" flags="print,nozoom,norotate" name="c55ed7ca-39c2-67f1-e769-29addd68c7c7" title="Nikhil" subject="Comment" date="D:20230503120952+05'30'" creationdate="D:20230503120949+05'30'" icon="Comment" statemodel="Review">

<trn-custom-data bytes="{&quot;trn-mention&quot;:&quot;{\&quot;contents\&quot;:\&quot;comment\\n\&quot;,\&quot;ids\&quot;:[]}&quot;}"/>

<contents>comment
</contents><contents-richtext><body><p><span>comment
</span></p></body></contents-richtext></text></annots><pages><defmtx matrix="1,0,0,-1,0,3370" /></pages></xfdf>`;

onRemoving the below line.:
<trn-custom-data bytes="{&quot;trn-mention&quot;:&quot;{\&quot;contents\&quot;:\&quot;comment\\n\&quot;,\&quot;ids\&quot;:[]}&quot;}"/>

When we remove above line of code from our response, annotation are retaining else it is not.
And also for some time <trn-…> portion of line are not including in the annotation response and sometime it is
Can you clarify why?Preformatted text

Hello nikhilhill19,

The trn-custom-data is basically data we inject into the XFDF to apply styling, line breaks, etc for some annotations. For this case, we are adding it for the FreeText annotation that is created to keep track of the line breaks.

We don’t do this for all annotations, only some

Best regards,
Tyler

But still we are not able to retain annotation if “trn-custom-data” is present in our respone,but removing that we are able to do so.Kindly provide with some solution to overcome this problemn.

We are importing using below command,which is working.
inst.Core.annotationManager.importAnnotations(data);

We are exporting annotation response from below code:

const vv = inst.Core.annotationManager
            .getAnnotationsList()
            .filter((annot) => annot.Subject === "Comment");
          console.log("anew", vv);
          const xfdf = await inst.Core.annotationManager.exportAnnotations({
            //   // annotList: [inst.Core.Tools.TextHighlightCreateTool],
            annotList: vv,
          });

          console.log(xfdf);

With trn-custom-data:

const data = `<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><annots><text page="0" rect="287.070,631.750,318.070,662.750" color="#FFCD45" flags="print,nozoom,norotate" name="c41d27c6-4909-f4fa-8d1b-8f0a95d6f9ee" title="Nikhil" subject="Comment" date="D:20230424102240+05'30'" creationdate="D:20230424102224+05'30'" icon="Comment" statemodel="Review">
            <trn-custom-data bytes="{&quot;trn-mention&quot;:{&quot;contents&quot;:&quot;Need to Change some information&quot;,&quot;ids&quot;:[]}}"/><contents>data1</contents>
            <contents-richtext><body><p><span>Change the layer
            </span></p></body></contents-richtext></text><text page="1" rect="249.450,130.250,280.450,161.250" color="#FFCD45" flags="print,nozoom,norotate" name="c06f5bd3-e309-cc96-4105-5f46e07e797f" title="Nikhil" subject="Comment" date="D:20230504102056+05'30'" creationdate="D:20230504102053+05'30'" icon="Comment" statemodel="Review"><trn-custom-data bytes="{&quot;trn-mention&quot;:&quot;{\&quot;contents\&quot;:\&quot;rrrr\\n\&quot;,\&quot;ids\&quot;:[]}&quot;}"/><contents>rrrr
</contents><contents-richtext><body><p><span>rrrr
</span></p></body></contents-richtext></text></annots></xfdf>`;

Without trn-custom-data:

  const data = `<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><annots><text page="0" rect="287.070,631.750,318.070,662.750" color="#FFCD45" flags="print,nozoom,norotate" name="c41d27c6-4909-f4fa-8d1b-8f0a95d6f9ee" title="Nikhil" subject="Comment" date="D:20230424102240+05'30'" creationdate="D:20230424102224+05'30'" icon="Comment" statemodel="Review">
            <trn-custom-data bytes="{&quot;trn-mention&quot;:{&quot;contents&quot;:&quot;Need to Change some information&quot;,&quot;ids&quot;:[]}}"/><contents>data1</contents>
            <contents-richtext><body><p><span>Change the layer
            </span></p></body></contents-richtext></text><text page="1" rect="249.450,130.250,280.450,161.250" color="#FFCD45" flags="print,nozoom,norotate" name="c06f5bd3-e309-cc96-4105-5f46e07e797f" title="Nikhil" subject="Comment" date="D:20230504102056+05'30'" creationdate="D:20230504102053+05'30'" icon="Comment" statemodel="Review"><contents>rrrr
</contents><contents-richtext><body><p><span>rrrr
</span></p></body></contents-richtext></text></annots></xfdf>`;

Removed linne:
<trn-custom-data bytes="{&quot;trn-mention&quot;:&quot;{\&quot;contents\&quot;:\&quot;rrrr\\n\&quot;,\&quot;ids\&quot;:[]}&quot;}"/>

Hi nikhilhill19,

Is there a specific error you’re getting? in the console?
Are you able to provide a sample project to reproduce the issue?

Best regards,
Tyler

No we are not getting any error but annotation are not retaining.
Below is the code:
Project.zip (1.7 KB)

Hi nikhilhill19,

Theres a few things I can point out in the code that could cause some issues:

  1. The XFDF with the trn-custom-data has incorrect JSON, this is typically from copying XFDF straight from the browser console (which is a Chrome issue, for some reason it adds &quot; before every quotation), we generally do not recommend copying XFDF manually, instead saving it with calling:
    copy(await instance.Core.annotationManager.exportAnnotations())
    to get around the text copying issue.
  2. Youre calling importAnnotations on an empty string:
    const data2 = ``;
    ...
    inst.Core.annotationManager.importAnnotations(data2);

Unfortunately, I cant reproduce this issue without a runnable sample project, since your code requires specific files.

Best regards,
Tyler