Clarification Needed: Is there anyway to remove annotations?
Is there any way to remove all annotations or a specific annotation?
We could also use a pagebuilder and try to copy the page manually to a copy of the same PDF, post which if annotations are accessible, then it can be removed. Is there any other harder way (lookup any dictionary to process those), please let know.
PdfPig doesn't expose an easy way to modify existing pdfs / pages. The pagebuilder lets you add to existing pages but the the lower level pdf objects aren't exposed to be modified before saving.
You could probably accomplish it by:
- Opening the pdf and accessing the raw PdfObjects through the
Document.Structure.Catalog.PageTree - Modifying the pdf dictionaries for the pdf pages, removing the annotations
- Replace pdf page dicts by xref using
Document.Advanced.ReplaceIndirectObject(xRefToken, newObject) - Use
PdfDocBuilder.AddPage(pdfDoc, pageNum)to copy the pages over ... should pick up the replaced objects
Honestly PdfSharp or other modification libraries are probably a better fit for this type of thing. At one point I was looking at adjusting PdfPig to allow easier modification but would take a significant refactor.
@plaisted Thank you for the notes. Yes, modifying page builder seems limited now. However, tried the #2, basically dropping the ANNOTS token from the dictionary after copying the page seems to help. Would check if #3 helps.
Please close this ticket if it's not a planned item since the above will help.