Detect any pdf modifications

Product:
pdftron/webviewer

Product Version:
8.1.0

Please give a brief summary of your issue:
Detect any pdf modifications

Please describe your issue and provide steps to reproduce it:
I try to detect any kind of modifications on a document to implement a “Do you discard modifications?” message if a user modified a document and leave the editor. But I’m not sure if i detect all possible modifications at the moment.

Detect pdf document modifications it self:

 const doc = instance?.Core.documentViewer.getDocument();
 const pdfDoc = await doc.getPDFDoc();
 const modified = await pdfDoc.isModified();

Detect annotation modifications:

instance.Core.annotationManager.addEventListener('annotationChanged', ...
instance.Core.annotationManager.addEventListener('annotationCreated', ...
instance.Core.annotationManager.addEventListener('dnnotationDeleted', ..

But I guess, there are multiple additional ways to modify a PDF like AcroForms etc.

Is there a general function to detect any kind of modifications?

Best regards
Uli

1 Like

Hi Uli,

There isn’t a single event that you can listen to for this. Likely you would need to listen to multiple events. Here are some events that may be what you are looking for:
annotationChanged
fieldChanged
layoutChanged

Let me know if there are any issues.

Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

Hi Ahmad,

thanks for your response.
I just try it but I get the following effect:
If I open a huge linearized document, I can already add annotations before the document and the annotations is fully loaded. This triggers annotationChanged with action add. As I expected it.

But I get also the same event, if I just open a document with existing annotations. So I can’t detect if a user added the annotation or it is a existing and unchanged annotation.

Is there a way to detect the source of the event?

Best regards
Uli

Hi Uli,

The annotationChanged event passes an info object to the callback which contains the imported property. If imported is true then this change was most likely triggered from within the document itself. You can check for that property and ignore the event in that case.

Let me know if there are any issues.

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com