In our latest iText Core version 8 release, we’ve added a simple, yet highly configurable way to flatten annotations! It’s now much easier to flatten PDFs for further processing or archiving, as it can be done with just a couple of lines through the new
PdfAnnotationFlattener (Java/.NET) class introduced in iText Core 8.0.2.
Here’s a quick example:
Default Flatten Example
Default Flatten By List Example
PdfAnnotationFlattener class also accepts a list of annotations to be flattened, which is useful if you would only like to flatten certain types of annotation. In this example, we can add only underline annotations to be flattened and the rest of the annotations will be left untouched.
Customized Flatten Example
That’s by no means all though. We also offer customizability options for our
PdfAnnotationFlattener class through custom methods that can be passed to the factory, allowing for flexibility in the way specific widget types are flattened.
In this example, we can customize the flattener to draw all square annotations as blue rectangles for better visibility, instead of flattening them normally.
Here is the sample file used for these examples if you would like to try it yourself: