2025-04-24 16:00:16 +02:00

36 lines
1.2 KiB
VB.net

Imports System.IO
Imports GdPicture14
Public Class FlattenFormFields
Public Shared Function FlattenFormFields(pFilePath As String) As String
Dim oFolder As String = Path.GetDirectoryName(pFilePath)
Dim gdpicturePdf As GdPicturePDF = New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePdf.LoadFromFile(pFilePath, True)
If status = GdPictureStatus.OK Then
Dim oFormFieldsCount = gdpicturePdf.GetFormFieldsCount()
If oFormFieldsCount > 0 Then
gdpicturePdf.FlattenFormFields()
Dim newFilesPath As String = Path.Combine(oFolder, "InputFieldsFlattend_" & Path.GetFileName(pFilePath))
If gdpicturePdf.SaveToFile(newFilesPath) = GdPictureStatus.OK Then
Dim oNameofFile = Path.GetFileName(newFilesPath)
MsgBox("Your PDF-file contained form-fields!" & vbNewLine & "We needed to adapt the file and created an new version!" & vbNewLine &
$"New filename: {oNameofFile}", MsgBoxStyle.Exclamation, "Information")
Return newFilesPath
End If
End If
End If
Return pFilePath
End Function
End Class