Link to home
Create AccountLog in
Avatar of kdeutsch
kdeutschFlag for United States of America

asked on

Find form fields in pdf file

I am trying to find out what the names of the fields are in a pdf file so that I can push data to them from my asp page.  I can see the file and save the fiel but I have no clue what the field names are.  Serched high and wide on web and every suggestion i use has dictionaryEntry which always errors out on me

itextsharp.text.pdf.acrofieldsItem cannot be converted to systems.collections.dictionary entry


 Private Sub ListFieldNames()
        Dim pdftemp As String = Server.MapPath("~/PDF/test.pdf")

        Dim pdfReader As PdfReader = New PdfReader(pdftemp)

        ' create and populate a string builder with each of the
        ' field names available in the subject PDF
        Dim sb As New StringBuilder()

        Dim de As New DictionaryEntry
        For Each de In pdfReader.AcroFields.Fields
            sb.Append(de.Key.ToString() + Environment.NewLine)
        Next

        ' Write the string builder's content to the form's textbox
         response.write(sb)

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of kdeutsch

ASKER

Hi CodeCruiser,

Thanks for reply that does work, however it only get the fields on the second page of the form, it never shows the fields on the 1st page of the forms.  tried on a standard w-4 form from IRS and a form template from pdf creator and both same.  Doe snto get fields of the 1st page.

Heres what it returned for a standard w-4 form and i mapped all fields to 2nd page of form.


topmostSubform[0].Page2[0].f2_06_0_[0]
topmostSubform[0].Page2[0].f2_07_0_[0]
topmostSubform[0].Page2[0].f2_08_0_[0]
topmostSubform[0].Page2[0].f2_09_0_[0]
topmostSubform[0].Page2[0].f2_10_0_[0]
topmostSubform[0].Page2[0].f2_11_0_[0]
topmostSubform[0].Page2[0].f2_12_0_[0]
topmostSubform[0].Page2[0].f2_13_0_[0]
topmostSubform[0].Page2[0].f2_14_0_[0]
topmostSubform[0].Page2[0].f2_15_0_[0]
topmostSubform[0].Page2[0].f2_16_0_[0]
topmostSubform[0].Page2[0].f2_17_0_[0]
topmostSubform[0].Page2[0].f2_18_0_[0] .
topmostSubform[0].Page2[0].f2_19_0_[0]
What happens if you fill these fields?
hi,

I filled them in, they are the last fields on the last page of the PDF file,  I tired 3 differetn pdf to try to get fields, always if there are more than 1 page in pdf file, it only gives the last pages fields.
Your code seems correct. Do you still only see those last page fields if you write to a file instead of

response.write(sb)

?
Hi,
Yep both ways, same result.  I have since cracked the pdf and redid it so that I can see the form fields, I think it had to do with encyption of documents and such and password protected.
I have a follow on question that I am posting you might be able to help with.
Thanks