kdeutsch
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.acrofi eldsItem cannot be converted to systems.collections.dictio nary 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.Field s
sb.Append(de.Key.ToString( ) + Environment.NewLine)
Next
' Write the string builder's content to the form's textbox
response.write(sb)
End Sub
itextsharp.text.pdf.acrofi
Private Sub ListFieldNames()
Dim pdftemp As String = Server.MapPath("~/PDF/test
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.Field
sb.Append(de.Key.ToString(
Next
' Write the string builder's content to the form's textbox
response.write(sb)
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
What happens if you fill these fields?
ASKER
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.
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)
?
response.write(sb)
?
ASKER
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.
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.
ASKER
I have a follow on question that I am posting you might be able to help with.
ASKER
Thanks
ASKER
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]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]
topmostSubform[0].Page2[0]