How to avoid non-printing items from printing after flattening PDF

Viewed 24

I recently upgraded from iText5 to iText7.

I'm using iText7 to flatten documents to remove interactivity. I expected that the printed document would look the same before and after flattening. Unfortunately that's not the case.

The source pdf has non-printing Button objects that are set to "Visible but doesn't print". After flattening, the undesired fields do print.

Is there a setting I'm missing, or do I need to remove non-printing buttons, fields etc before flattening?

Public Shared Function FlattenPdf(SourcePath As String, DestPath As String) As String

    Using reader As New Pdf.PdfReader(SourcePath)
        Using writer As New Pdf.PdfWriter(DestPath)

            'Opens PDF document in the stamping mode
            Dim pdfDoc As New Pdf.PdfDocument(reader, writer)
            Dim form As Forms.PdfAcroForm = Forms.PdfAcroForm.GetAcroForm(pdfDoc, createIfNotExist:=True)

            'flatten the form to remove editing options 
            form.FlattenFields()

            pdfDoc.Close()
        End Using
    End Using

    Return DestPath
End Function
0 Answers
Related