linkedinfacebooktwittermenuarrow-up

GemBox Support Forum

Flattening Annotations

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

Hi Dave,

Can you please send us a sample file that has the mentioned “Applied Stamps”?
We will use it to reproduce your issue and investigate it.

Regards,
Mario

Hello, I think it was another issue with that pdf. It would open in other programs (Nitro, Bluebeam etc) and bluebeam actually said their was a problem with the viewports??? Anyway, I think it is just one bad pdf that I just happened to use for testing. If it comes up again I will send it in.

This issue was resolved with this bugfix version:
https://www.gemboxsoftware.com/pdf/nightlybuilds/GBA17v1212.zip

And this NuGet package:
Install-Package GemBox.Pdf -Version 17.0.1212-hotfix