Hello, I have some pdf files that I would like to flatten the annotations and have tried to modify the code in the flatten forms example. When I run the code it will work on some files but on some I end up with a blank file. The ones that are blank have “Applied Stamps” and I have tried doing some tests with some other stamps and they work. Am I missing something in my code? Should this work with stamps?
Using document = PdfDocument.Load(vPath)
' A flag specifying whether to construct appearance for all form fields in the document.
Dim needAppearances = document.Form.NeedAppearances
For Each vP As PdfPage In document.Pages
For Each vA In vP.Annotations
' Do not flatten button fields.
'If field.FieldType = PdfFieldType.Button Then Continue For
' Construct appearance, if needed.
If needAppearances Then vA.Appearance.Refresh()
' Get the field's appearance form.
Dim fieldAppearance = vA.Appearance.Get()
' If the field doesn't have an appearance, skip it.
If fieldAppearance Is Nothing Then Continue For
' Draw field's appearance on the page.
vA.Page.Content.DrawAnnotation(vA)
Next
vP.Annotations.Clear()
Next
' Remove all fields, thus making the document non-interactive,
' since their appearance is now contained directly in the content of their pages.
'document.Form.Fields.Clear()
document.Save("Flattened.pdf")
End Using