downloadPdf adds the watermark multiple times

Hello,

I have a function to download the PDF with a watermark:

private download(){
  this.webViewerInstance.Core.documentViewer.getDocument().setWatermark({ footerRight: { fontSize: 20, fontFamily: "arial", color: "red", opacity: 50, text: "hello" } });
  this.webViewerInstance.UI.downloadPdf({ filename: "test.pdf", includeAnnotations: true });
}

If I call it twice, the watermark will be drawn twice. you can notice this by observing the opacity or by changing the text.
Screenshot 2023-12-22 at 14.04.42


If I clear the watermark after downloadPdf, no watermark at all will be added.

private download(){
  this.webViewerInstance.Core.documentViewer.getDocument().setWatermark({ footerRight: { fontSize: 20, fontFamily: "arial", color: "red", opacity: 50, text: "world" } });
  this.webViewerInstance.UI.downloadPdf({ filename: "test.pdf", includeAnnotations: true });
  // clear the watermark
  this.webViewerInstance.Core.documentViewer.getDocument().setWatermark({});
}

waiting for the promise to resolve doesn’t work either, the watermark will be drawn twice

private download(){
  this.webViewerInstance.Core.documentViewer.getDocument().setWatermark({ footerRight: { fontSize: 20, fontFamily: "arial", color: "red", opacity: 50, text: "world" } });
  this.webViewerInstance.UI.downloadPdf({ filename: "test.pdf", includeAnnotations: true }).then(e => {
      this.webViewerInstance.Core.documentViewer.getDocument().setWatermark({});
  });
}

Is this a bug or is there a correct way to clear the watermark?

WebViewer Version: 10.6

1 Like

Thank you for posting your question to our forum. We will provide you with an update as soon as possible.

1 Like

Hello elia.kocher,

Since this is a custom implementation, we are unable to reproduce the issue on our end. Can you please open a support ticket at: Support : Apryse
and if at all possible, provide us with a minimal runnable reproducible sample of your project.

You can read more about watermarks here: Apryse Documentation | Documentation

*A minimal runnable reproducible sample refers to a simplified version of your project where unrelated/unnecessary code has been removed. The issue should still be reproducible in this simplified version.

This helps us isolate and understand the problem more efficiently. You can attach your project here or provide us with a download link or GitHub repo.

1 Like

thank you bjovanovic, I have opened a support ticket

1 Like

The solution to this problem is to make a copy of the underlying document, and then apply the watermark.
Here a working code example:

private async download() {
    const doc = webViewerInstance.Core.documentViewer.getDocument();
    const docData = await doc.getFileData({ xfdfString: await this.webViewerInstance.Core.annotationManager.exportAnnotations() });
    const newDoc = await this.webViewerInstance.Core.createDocument(docData, { extension: 'pdf' });
    newDoc.setWatermark({ "footerRight": { "fontSize": 20, "fontFamily": "arial", "color": "red", "opacity": 50, "text": "Hello world" } });
    this.webViewerInstance.UI.downloadPdf({
        filename: "test.pdf",
        documentToBeDownloaded: newDoc
    }).then(e => { });
}
1 Like

Hi Elia,
Thank you for providing the code snippet and the explanation. Should we consider this matter solved and close this ticket?

1 Like

Yes this can be considered as solved.

1 Like