How to selectively flatten certain annotations?


How do I manually, selectively flatten annotations? There are some I don’t want to flatten, so I can’t use PDFDoc.FlattenAnnotations.


for (PageIterator itr = in_doc.getPageIterator(); itr.hasNext(); ) {
Page page = (Page)(;
// need to draw from first to last, but flatten removes the annotation, so getNumAnnots drops.
// therefore don't increment index counter on flattening
for (int i = 0; i < pages.getNumAnnots();) {
        Annot annot = page.getAnnot(i);
        if( /* your conditional here */ ){ // if you (don't) want to flatten fields, check for annotations of the Widget type.
        } else {
        } catch(Exception ex) {
            // bad annotation. Remove since flattening failed.

What can I condition can I put in there? I wanted to check for the form field name.

To get the full form field name use Field.GetName()

Full forms sample code here