Can't clear Signature after saving document

Hello,

after my last issue has been resolved, I’ve ran into a new one. Hopefully this will be the last thread from me, since the implementation of Apryse is almost done.

In the document there are two signature fields. When I close the WebViewer, the document gets saved like this:

const doc = documentViewer.getDocument();
const xfdfString = await annotationManager.exportAnnotations();
const options = { xfdfString };
const data = await doc.getFileData(options);
const arr = new Uint8Array(data);
this.finalBlob = new Blob([arr], { type: ‘application/pdf’ });
this.closePage(this.finalBlob, signatureAdded);

I want the added signatures to be deleted, if the document gets opened in the WebViewer again.
I’ve tried it like this:

documentViewer.addEventListener(‘annotationsLoaded’, () => {
const signatureWidgetAnnots = annotationManager.getAnnotationsList()
.filter(annot => annot instanceof Annotations.SignatureWidgetAnnotation) as Annotations.SignatureWidgetAnnotation;
signatureWidgetAnnots.forEach(annot => {
annot.clearSignature(annotationManager);
});
});

However, this doesn’t work. So I added following console.log to check if the fields are signed:

console.log("annot signed: " + annot.isSignedByAppearance());

I put this console.log at the end of the saving process, right before this.closePage gets called and the output of isSignedByAppearance() is “true”.
I also put the same console.log to the beginning, right after annotationsLoaded. When I save the document, the output is “true”. When I then open it again in the WebViewer, the output is “false”.

So suddenly, the fields are not signed by appearance anymore.

Also, if i put the annot.clearSignature at the end of the saving process, so right before this.closePage, the method works and the signatures are cleared. But it doesn’t work when I put it at the start, after annotationsLoaded.

How can I fix that?

1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


It seems like you’re attempting to clear signatures from signature fields in a PDF document when it is reloaded in the WebViewer. The issue may arise from the timing of when the annotations are being cleared. Since the annotationsLoaded event is triggered once all annotations are loaded, it’s crucial to ensure that any operations on the annotations are executed after this event has fully completed.

Some things you can try:

  • Ensure the annotationsLoaded event listener is properly set up and triggered after all annotations are fully loaded.

  • Verify that the signature fields are correctly identified as SignatureWidgetAnnotation instances before attempting to clear them.

  • Consider using the annotationsLoaded event to trigger a function that checks and clears the signatures only if they are present and signed.

  • Ensure that the clearSignature method is being called on objects that are indeed signature annotations.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

Hello Marvin,

Thank you for contacting WebViewer Forums.

I was able to run the provided code but was not able to replicate the issue. To investigate further, can you provide a sample PDF document with the signatures where isSignedByAppearance() is false and a separate document where it returns true?

Regards,
Luke

1 Like

Hello Luke,

I can’t provide two sample PDF like you suggested, since the same PDF that returns “true” when saving, then returns “false” as soon as I open the document in the WebViewer again.

When the document is saved into a blob and the closePage method gets called, this is what happens:

closePage(finalBlob: Blob, signatureAdded: boolean) {
const reader = new FileReader();
reader.onloadend = () => {
const base64data = reader.result as string;
const [, base64String] = base64data.split(‘,’);
this.viewCtrl.dismiss({ success: signatureAdded, daten: base64String });
};
reader.readAsDataURL(finalBlob);
}

The document is converted into base64 for further actions in our application. Could this maybe cause the information of isSignedByAppearance to get lost?

1 Like

Hello Marvin,

A sample document with it returning false will work fine. It is hard to say whether converting it from blob to base64 would have any impact. Inspecting the document and annotation will provide a better understanding of the issue.

Regards,
Luke

1 Like

myfile (1).pdf (37.7 KB)

I attached a sample PDF which I have signed and isSignedByAppearance returns false.

1 Like

Hello Marvin,

Thank you for the file.

I have checked with our latest WebViewer version 11.5 and it returns true. Please see the following:

To investigate further, could you provide your current WebViewer version and does updating to the latest version show any changes?

Regards,
Luke

1 Like

The Version was 11.4 but I updated to 11.5 now, however that didn’t fix the problem.

I attached my complete implementation of Apryse for further investigation (only deleted the license key).

You’ll see two occasions of isSignedByAppearance:

In line 70 and line 146.
The one in line 146 shows “true” after signing the fields and closing the WebViewer. The one in line 70 shows “false” when I open the document in the WebViewer again.

Notice that I set the document to readOnly when it’s signed, but if the condition in line 48 is matched, READ_ONLY is set to false to be able to edit the document again.

Maybe you can reproduce the problem with my implementation. Hope that helps.

apryse.ts (6.9 KB)

1 Like

Hello Marvin,

Thank you for the file.

There seems to be a timing issue when calling isSignedByAppearance() within the annotationsLoaded listener. It may be possible the widget has not fully rendered yet which is returning the false positive.

I was able to set a timeout delay before calling isSignedByAppearance() and noticed the issue is resolved. For example:

setTimeout(() => {
          const signatureWidgetAnnots = annotationManager
            .getAnnotationsList()
            .filter(
              (annot) => annot instanceof Annotations.SignatureWidgetAnnotation
            );

          signatureWidgetAnnots.forEach((annot) => {
            console.log('annot signed1: ' + annot.isSignedByAppearance());
          });
        }, 1000);

We will continue to investigate the timing issue here and provide you with an update.

Regards,
Luke

1 Like

That workaround seems to fix it for me, thank you!
I’ll be happy to hear from you again if/when you have an update on the issue.

1 Like