Discard the PDFTron new Annotation added in document

Product: PDFTron

Please give a brief summary of your issue:
(Think of this as an email subject)

We have the requirement to discard the changes done using the annotation toolbar.

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

  1. Open the document on edit mode (there might be older annotations added)
  2. Add new annotations to the document.
  3. On the cancel button → I want to restore the previous state of the document
    On Save Button → I want to save the document
    Current it is the same file path that is downloaded from the server.

We tried through undo manager which takes some to discard the changes done on the document
while pdfViewCtrl.undoManager?.canUndo == true {
pdfViewCtrl.undoManager?.undo()
}

Is there any approach available to Discard the new annotations added in the document?

Thanks

Thank you for getting in touch with us.

To clear all changes in a PTPDFViewCtrl, you can use the following code:

do {
    try pdfViewCtrl.docLock(true) { doc in
        pdfViewCtrl.revertAllChanges()
        pdfViewCtrl.update(true)
    }
} catch {}
pdfViewCtrl.undoManager?.removeAllActions()

Please let us know how the above works for you and if you have any questions.

Thank @dluco
This solution is works for me.