Hi,
I would like to flatten some of our custom annotations, but somehow not all of the SAME annotations are not recognized/valid.
First, I merge the annotations (as XFDF) with a document, using this code (see here an example XFDF file):
`
public static InputStream mergeDocumentsAndAnnotations(Document document) {
FileInputStream pdf = FileSystem.getFileInputStream(document.getIdAlfrescoObject(), FolderEnum.DOCUMENTS);
PDFDoc in_doc = new PDFDoc(pdf);
in_doc.initSecurityHandler();
FDFDoc fdoc = FDFDoc.createFromXFDF(document.getXfdfData());
in_doc.fdfMerge(fdoc);
flattenAnnotations(in_doc.getPageIterator());
ByteArrayOutputStream merged = new ByteArrayOutputStream();
in_doc.save(merged, SDFDoc.e_linearized, null);
byte[] b = merged.toByteArray();
return new ByteArrayInputStream(b);
}
`
Within this method, I try to flatten the annotations onto the document:
`
public static void flattenAnnotations(PageIterator itr) {
while (itr.hasNext()) {
Page page = (Page) (itr.next());
int num_annots = page.getNumAnnots(); // RETURNS CORRECT AMOUNT OF ANNOTATIONS
play.Logger.info(String.valueOf(num_annots));
for (int i = 0; i < num_annots; i++) {
Annot annot = page.getAnnot(i);
if (annot.isValid()) { // SOME OF THE SAME ANNOTATIONS ARE NOT VALID
Markup markup = new Markup(annot);
annot.flatten(page);
}
}
}
}
`
The exampe XFDF file above contains 4 annotations, but not all annotations are “valid”, although identical. Only 2 are valid and are available for flattening. If I remove the isValid() check, I get NullpointerExceptions.
What defines if a annotation is valid or not? The annotations in the XFDF file are identical (except the creation date), why are some valid and some not?
I use libPDFNetC.so.6.7.1 and the Java library.
What am I missing here? Or is there a bug?