>>Here's some code I'm using in production. There is an imports statement and iTextsharp.dll is included as a reference
>>This goes through every PDF form in a folder and returns a report of all the fields found. ( not their contents, the field names)
>>
>>I think this is the only line that uses iTextsharp in this routine
>>
>> pdffields = GetPDFFormFields(pdffile)
>>
>>
>>I have a version I'll be happy to post that produces a complete report of distinct field names found in all the PDFs in order to determine what datapoints need to be available.
>>
>>If you google itextsharp c# tutorial you should find lots of information on how to use iTextsharp to extract whatever you need from pdfs or to create pdfs on the fly or fill pdfs fields.
>>
>>There is also something called antlr I am using and I am now researching to see what I use it for and if it would help in what you're doing . I'll get back to you on that.
>>
>>Are you primarily interested in reading data from PDF forms that others have filled in or are you going to be filling out pdf forms from data ( I do mostly the latter )
>
>I am reading only. And, we have no idea about the field names. So, I need to get all the field names in a collection. Then, by deduction, we will be able to see what field we need to use. We have 10 sample PDF files. So, when I will extract the related value, I will be able to see if the proper field name was used.
Yes that is very much like the situation I had and this worked very well.
Here is the code to get a distinct list of all the fields for all the forms in the folder
(actually in this one I am iterating the business object that holds the metadata for the PDFs in the folder, but you get the idea )
Public Sub Allfieldslist()
Dim Allfieldlist As List(Of String) = New List(Of String)
Me.CarriersBO1.SeekToPrimaryKey(Me.cboCarriers.SelectedValue)
With Me.PdfFormsBO1
Dim oldfiltstr As String = .Filter
.Filter = String.Format("{0} = {1}", "icarrierskey", Me.CarriersBO1.ikey)
For Each bo In Me.PdfFormsBO1.GetEnumerable()
Dim _
FieldsArray As String() = _
Me.PdfFormsBO1.PDFFormFields.Split(New String() {ControlChars.NewLine, ",", ";"}, _
StringSplitOptions.RemoveEmptyEntries)
For Each fld As String In FieldsArray
If Not Allfieldlist.Contains(fld) Then
Allfieldlist.Add(fld)
End If
Next
Next
.Filter = oldfiltstr
End With
Dim myWriter As StreamWriter
Dim myStream As FileStream
Dim outfile As String = Path.Combine(Me.CarriersBO1.PDFFormPath, Me.CarriersBO1.Carrier & "fields.txt")
myStream = New FileStream(outfile, FileMode.Create)
myWriter = New StreamWriter(myStream)
Allfieldlist.Sort()
Dim field As String
For Each field In Allfieldlist
myWriter.Write(field.ToString)
myWriter.WriteLine()
Next
myWriter.Close()
myStream.Close()
Process.Start(outfile)
End Sub
Charles Hankey
Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy
Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.
-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin
Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.