iOS: XFDF does not persist deletion when all annotations are removed (last annotation cannot be deleted)

Product: PDFTron.iOS and PDFTron.iOS.Tools

Product Version: 11.3.0

Please give a brief summary of your issue:
We are facing a consistent issue in PDFTron iOS where annotation deletions are not persisted when all annotations are removed from a document.

Please describe your issue and provide steps to reproduce it:
Observed behavior:

  1. If a PDF contains N annotations:

    • Deleting N-1 annotations works correctly

    • The remaining annotations are saved properly via XFDF

  2. However:

    • The last remaining annotation cannot be deleted

    • If all annotations are erased at once, none of the deletions are persisted

    • On reopening the document, all annotations reappear

  3. This behavior is not related to a specific annotation type:

    • It occurs for ink, shapes, comments, etc.

    • Any single annotation can act as the “last one”

    • At least one annotation must remain for deletions to persist

Expected Behavior

  • Deleting all annotations should result in:

    • XFDF correctly representing an empty annotation state

    • Reopening the document with zero annotations

Actual Behavior

  • When annotation count reaches zero:

    • PDFDoc.FDFExtract(e_annots_only).SaveAsXFDF() does not reflect deletions

    • The last annotation appears to be deleted visually but is not persisted

    • XFDF export does not represent the “all annotations deleted” state

Reproduction Steps

  1. Open a PDF with multiple annotations

  2. Erase all annotations

  3. Save annotations using XFDF export

  4. Reload document / reapply XFDF

Result:
All annotations reappear

Control case:
If at least one annotation remains → deletions persist correctly

Please provide a link to a minimal sample where the issue is reproducible:

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 you’re encountering an issue with persisting annotation deletions in PDFTron iOS when all annotations are removed. This is a known challenge that can occur due to the way XFDF handles empty annotation states. The core of the problem lies in ensuring that the XFDF export accurately reflects the deletion of all annotations.

Some things you can try:

  • Ensure you are calling doc.Save() after removing annotations and before exporting XFDF to ensure the document state is updated.

  • Verify if the issue persists when using doc.RefreshAnnotAppearances() before exporting XFDF.

  • Consider manually clearing the annotations using the doc.GetPage(pageNumber).GetAnnots().Clear() method before saving the XFDF.

  • Check if re-importing the XFDF after deletion correctly updates the document state.

  • Try using doc.GetPage(pageNumber).FlattenAnnotations() to see if it affects the persistence of deletions.



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.

Thank you for reaching out through our Forum. In order to best assist you, would you be able to provide a minimal runnable sample project along with the XFDF that you are seeing issues with? You can submit a support ticket here: Submit a ticket : Apryse
I look forward to further assisting you.