How to selectively flatten certain annotations?

111 views
Skip to first unread message

Ryan

unread,
Jul 19, 2017, 5:20:33 PM7/19/17
to PDFTron PDFNet SDK
Question:

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

Answer:

for (PageIterator itr = in_doc.getPageIterator(); itr.hasNext(); ) {
   
Page page = (Page)(itr.next());
   
// 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();) {
       
try{
           
Annot annot = page.getAnnot(i);
           
if( /* your conditional here */ ){ // if you (don't) want to flatten fields, check for annotations of the Widget type.
                annot
.flatten(page);
           
} else {
               
++i;
           
}
       
} catch(Exception ex) {
           
// bad annotation. Remove since flattening failed.
           page
.annotRemove(i);
       
}
   
}
}

Anuj Agrawal

unread,
Nov 13, 2019, 2:05:15 PM11/13/19
to PDFTron PDFNet SDK
What can I condition can I put in there? I wanted to check for the form field name.

Ryan

unread,
Nov 14, 2019, 2:35:59 PM11/14/19
to PDFTron PDFNet SDK
Reply all
Reply to author
Forward
0 new messages