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

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]&rep=127,48

Code snippet
{Provide a relevant code snippet}

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

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!

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 });
};
});

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?

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

Hey there!

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

For now, a workaround is to call

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

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

1 Like