I would like to replace all annotations that exist in my PDF document. I'm attempting to do that by executing the following code...
// The PDF document w/ annotations
PDFDoc myDoc;
// The new annotations to be loaded into the PDF
FDFDoc newAnnotations;
// Iterate through all of the document's pages to first delete
// any / all annotations that already exist
for (int pageIdx = 1; pageIdx <= pdfDoc.getPageCount(); pageIdx++)
{
Page currPage = myDoc.getPage(pageIdx);
if (currPage.getNumAnnots() > 0)
{
currPage.getSDFObj().erase("Annots");
}
}
// Load the new annotations into the
// document
myDoc.fdfMerge(newAnnotations);
After executing the above code my document contains 0 annotations. The above code works if the source PDF document doesn't already contain annotations. It appears to only not work when I'm first removing already existing annotations. Am I doing something wrong? Is there a better way to accomplish what I've described?