How do I flatten PDF annotaions and fields?

Q: How do I flatten PDF annotaions and fields using PDFNet SDK (http://
A: You can flatten any annotation type using Annot.Flatten() method.
Please note that annotations must be flattened in the reverse order
(since Annot.Flatten() method removes the object from the annotation
array in the page dictionary).

For example:

// In C++:
try {
  PDFDoc doc("in.pdf");
  for (PageIterator pitr = doc.GetPageIterator(); pitr.HasNext();
pitr.Next()) {
    Page page = pitr.Current();
    for (int j=page.GetNumAnnots()-1; j>=0; --j) {
      Annot ann = page.GetAnnot(j);

  doc.Save("out.pdf", 0, 0);
catch(Common::Exception& e) {
  cout << e << endl;
  ret = 1;

// In VB.NET

Imports System
Imports pdftron
Imports pdftron.Common
Imports pdftron.SDF
Imports pdftron.PDF

Module Module1
  Sub Main()
      Dim doc As PDFDoc = New PDFDoc("in.pdf")

      For i As Integer = 1 To doc.GetPageCount()
        Dim pg As Page = doc.GetPage(i)
        For j As Integer = pg.GetNumAnnots() - 1 To 0 Step -1
          Dim ann As Annot = pg.GetAnnot(j)
      doc.Save("out.pdf", 0)
    Catch ex As PDFNetException
    Catch ex As Exception
    End Try
  End Sub
End Module