Download pdf with annotations(fields data + signatures)

PDF.js Express Version
7.1.2

Detailed description of issue
Trying to download PDF document with added annotations by WebViewer UI using instance.downloadPdf, but instead get a file without annotations.

Expected behaviour
To download document with annotations added in Viewer.

Link to document

Code snippet

    WebViewer(...)
  .then(function(instance) {
    var docViewer = instance.docViewer;
    var annotManager = instance.annotManager;

    // you must have a document loaded when calling this api
    docViewer.on('documentLoaded', async function() {
      // download pdf without annotations added by WebViewer UI
      instance.downloadPdf({
        includeAnnotations: false,
      });

      // download pdf with all annotations flattened
      instance.downloadPdf({
        includeAnnotations: true,
        flatten: true,
      });

      // download pdf without links
      const xfdfString = await annotManager.exportAnnotations({ links: false });
      instance.downloadPdf({
        xfdfString: xfdfString,
      });
    });
});

Hi!

PDF.js Express does not support flattening annotations on the client. To get this functionality, you can either use the merge rest API, or try out our sister product, PDFTron Webviewer (which has this functionality client side).

Thanks!
Logan

Thanks, @Logan

Could you please help with advice?
When I merged annotations with rest API, how is it possible to flatten it?
I want to get PDF document where all form fields and signature are read-only\static.

Hi there!

Before you export the annotations, you can loop over them and set them as readonly.

const { annotManager } = instance;
const list = annotManager.getAnnotationsList();

list.forEach(item => {
  item.ReadOnly = true
});

const xfdf = await annotManager.exportAnnotations();
...

Keep in mind that a lot of PDF viewers do not honour the ReadOnly flag, so the document may still be editable in some viewers.

Thanks!
Logan