Gerhard
Gerhard

Reputation: 339

Fill in data in a pdf form

Tried to use PdfSharp, using sample code shown here, nothing works.

I printed out a web document using Microsofts PrintToPdf Service available under Win 10, reading in ths document, but the AcroForm property is nothing, and so I fail.

What do I missing?

With best regards

Gerhard

Public Shared Sub test()

        Dim doc As PdfDocument = PdfReader.Open("C:\xxx\yyy.pdf", PdfDocumentOpenMode.Modify
        Dim form As PdfAcroForm = doc.AcroForm

        If doc.AcroForm.Elements.ContainsKey("/NeedAppearances") = False Then
            doc.AcroForm.Elements.Add("/NeedAppearances", New PdfSharp.Pdf.PdfBoolean(True))
        Else
            doc.AcroForm.Elements("/NeedAppearances") = New PdfSharp.Pdf.PdfBoolean(True)
        End If

        Beep()

    End Sub

Actual result is form is nothing (null in C#)

Upvotes: 1

Views: 2325

Answers (2)

Gerhard
Gerhard

Reputation: 339

Found a working solution. I get the NuGet packages PDFsharp and PDFsharp-MigraDoc. you can fill in a field like this :

Dim field As PdfTextField = DirectCast(myForm.Fields(fieldName), PdfTextField)
field.ReadOnly = False                                                                  ' Prepare the field for writing
field.Value = New PdfString(value)
field.ReadOnly = True                                                                   ' Seal the field to prvent user modifications
field.MultiLine = isMultiline

It works fine and it is free.

Upvotes: 3

j7m
j7m

Reputation: 1085

You probably already found the answer, but for future reference: AcroForm (or Acrobat Forms) is a form specification used to make forms on PDF files.

Your PDF is probably a flat file that doesn't have a form on it.

You can make an AcroForm of your PDF by using Adobe Acrobat Professional (paid) or the website PDFEscape (ad-supported)

Upvotes: 0

Related Questions