Saving Annotation Links

Hi Logan.

PDF.js Express Version

Detailed description of issue

When selecting a piece of content in a PDF, the popup menu allows the user to create a link. The initial selection of the text to annotation correctly creates an annotation for the highlight (or whatever) but adding a link to the annotation doesn’t trigger a resave so the link is lost after a page reload.

Expected behaviour
The saved data includes the link and the link continues working after a page reload.

Does your issue happen with every document, or just one?
It happens on every document I tried.



Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


Hey there,

Links in PDFs are just annotations, and PDF.js Express does not support merging annotations into the document client side. To do this, you need to use our Rest API to merge the link annotations into the document.


Thanks for the reply Logan and apologies for being slow to get back to you.

What I was meaning is this: when a link is added or deleted, it seemed to me that the normal call annotationChanged even isn’t fired. I’m now seeing that it is fired, but the data is quite different.

Thanks for the reply!

Actually, working on this further makes me realise I do still have a problem: the annotation object that’s returned is empty XML:

<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="" xml:space="preserve"><annots /></xfdf>

I’m expecting to see details of the link that was added, so that they can be saved and reloaded like other annotations.




You need to include links: true when exporting XFDF:

  instance.Core.annotationManager.addEventListener('annotationChanged', async (annots, action) => {
    if(action === 'add') {
      const annot = annots[0]
      if(annot instanceof instance.Core.Annotations.Link) {
        const xfdf = await instance.Core.annotationManager.exportAnnotations({
          annotList: [annot],
          links: true



Thanks Logan!

I see from the API documentation that there are also parameters for widgets and fields. Would they default to false too (the documentation doesn’t say what the default is). I assume the member of our team who implemented this thought a simple exportAnnotations call would give everything relevant without extra parameters. Would you consider changing the defaults so you do get everything by default (I’m not sure why you wouldn’t want links etc).