# Importing annotation issue

**URL:** <https://pdfjs.community/t/importing-annotation-issue/2562>\
**Category:** Bug Reports\
**Created:** [May 3, 2023, 6:48am UTC](https://pdfjs.community/t/importing-annotation-issue/2562 "2023-05-03T06:48:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikhilhill19](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@nikhilhill19](https://pdfjs.community/u/nikhilhill19)\
**Post date:** [May 3, 2023, 6:48am UTC](https://pdfjs.community/t/importing-annotation-issue/2562/1 "2023-05-03T06:48:40Z")

</div>

```javascript
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

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [May 3, 2023, 7:58pm UTC](https://pdfjs.community/t/importing-annotation-issue/2562/2 "2023-05-03T19:58:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nikhilhill19](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@nikhilhill19](https://pdfjs.community/u/nikhilhill19)\
**Post date:** [May 4, 2023, 5:05am UTC](https://pdfjs.community/t/importing-annotation-issue/2562/3 "2023-05-04T05:05:18Z")

</div>

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:

```javascript
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:

```javascript
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:

```javascript
  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;}"/>`

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [May 4, 2023, 6:59am UTC](https://pdfjs.community/t/importing-annotation-issue/2562/4 "2023-05-04T06:59:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nikhilhill19](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@nikhilhill19](https://pdfjs.community/u/nikhilhill19)\
**Post date:** [May 4, 2023, 7:45am UTC](https://pdfjs.community/t/importing-annotation-issue/2562/5 "2023-05-04T07:45:02Z")

</div>

No we are not getting any error but annotation are not retaining.  
Below is the code:  
[Project.zip](https://pdfjs.community/uploads/short-url/lFLrGnD9YSy4R7Y3jsTMkjNcmkg.zip) (1.7 KB)

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [May 5, 2023, 1:22am UTC](https://pdfjs.community/t/importing-annotation-issue/2562/6 "2023-05-05T01:22:30Z")

</div>

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:

```javascript
    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
