# Why it takes 2-3 minutes to save annotations to a PDF file?

**URL:** <https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563>\
**Category:** Technical Support\
**Created:** [March 4, 2021, 9:09am UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563 "2021-03-04T09:09:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SunnyTokyo](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@SunnyTokyo](https://pdfjs.community/u/SunnyTokyo)\
**Post date:** [March 4, 2021, 9:09am UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/1 "2021-03-04T09:09:01Z")

</div>

**PDF.js Express Version**  
“description”: “PDFJS Express”,  
“version”: “7.2.2”,

**Detailed description of issue**  
We use WebViewer to save annotations to a document, and we found that in some cases where PDF files with more than 30 pages costs 2-3 minutes to add and save only one small annotation. Is it expected situation or is there any faster practice?

**Expected behaviour**  
Other files are normally saved in a several seconds.

**Does your issue happen with every document, or just one?**  
It randomly occurs especially in the cases of larger sized PDF files.

**Link to document**  
[https://www.chugai-pharm.co.jp/cont\_file\_dl.php?f=FILE\_1\_48.pdf&src=[%0],[%1](https://www.chugai-pharm.co.jp/cont_file_dl.php?f=FILE_1_48.pdf&src=%5B%250%5D,%5B%251)]&rep=127,48

**Code snippet**  
{Provide a relevant code snippet}

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 4, 2021, 3:11pm UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/2 "2021-03-04T15:11:44Z")

</div>

Hey there!

PDF.js Express does not support saving annotations to a document. Are you using the REST API?

I’ll investigate in the meantime.

Thanks!  
Logan

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 4, 2021, 3:59pm UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/3 "2021-03-04T15:59:58Z")

</div>

Hey!

I’m unable to reproduce the slow saving times for that document.

Are you loading the document via URL? Can you send a code snippet showing how you are saving the PDF?

Thanks!

---

<div class="post-metadata">

**Author:** ![SunnyTokyo](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@SunnyTokyo](https://pdfjs.community/u/SunnyTokyo)\
**Post date:** [March 5, 2021, 12:27am UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/4 "2021-03-05T00:27:41Z")

</div>

Hi Logan! thanks for the quick reply!  
Let me correct the issue is not saving but exporting.  
The below exporting process costs around 2 min when adding some simple annotation to the document and export it.

WebViewer(  
{  
path: ‘/static/PDFJSExpress/lib’,  
initialDoc: \<\>,  
extension: ‘pdf’  
},  
document.getElementById(‘viewer’)  
).then(instance =\> {  
const { docViewer, iframeWindow, setHeaderItems } = instance;  
const annotManager = docViewer.getAnnotationManager();  
document.getElementById(‘save’).onclick = async (e) =\> {  
var xfdfString = await annotManager.exportAnnotations({ links: false, widgets: false });  
};  
});

---

<div class="post-metadata">

**Author:** ![SunnyTokyo](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@SunnyTokyo](https://pdfjs.community/u/SunnyTokyo)\
**Post date:** [March 8, 2021, 9:18am UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/5 "2021-03-08T09:18:06Z")

</div>

And we found out the latency occurs only on the first timing of annotManager.exportAnnotations.  
Once executed the above, there’s no latency of doing the same export. It looks like the module runs some heavy process on the first time, doesn’t it?

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 8, 2021, 5:54pm UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/6 "2021-03-08T17:54:48Z")

</div>

Hey there,

I can reproduce this issue now and will investigate. I’ll let you know what I find! My guess is that it is related to this specific file.

Thanks,  
Logan

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [March 8, 2021, 7:13pm UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/7 "2021-03-08T19:13:25Z")

</div>

Hey there!

This is a bug on our end that we’re working on resolving soon.

For now, a workaround is to call

```javascript
instance.docViewer.setEnableAutomaticLinking(false)

```

Whats happening is that we have some code that scans through the text and tries to add links to any text that resembles a URL - unfortunately this code is a bit slow on large documents like the one you sent me. Disabling this functionality with the API above fixes the issue.

Thanks for your patience,  
Logan

---

<div class="post-metadata">

**Author:** ![SunnyTokyo](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@SunnyTokyo](https://pdfjs.community/u/SunnyTokyo)\
**Post date:** [March 9, 2021, 1:11am UTC](https://pdfjs.community/t/why-it-takes-2-3-minutes-to-save-annotations-to-a-pdf-file/563/8 "2021-03-09T01:11:34Z")

</div>

Thank you Logan! We’ll be look forward to fixing the issue in the next version!
