Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading fields from PDF
Message
De
11/11/2011 14:00:09
 
 
À
11/11/2011 12:06:24
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01528652
Message ID:
01528682
Vues:
49
>>http://www.codeproject.com/KB/graphics/iTextSharpTutorial.aspx
>
>That links only discusses about creating a PDF. Does that utility capable of reading fields from PDF? If yes, do you know the Web site for more info on this. As, that link only contains a DLL. The DLL is probably OK but there is no info on reading fields.

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 )
Imports iTextSharp.text.pdf

    Public Sub getFieldsbyForm()

        Me.CarriersBO1.SeekToPrimaryKey(Me.PdfFormsBO1.iCarrierskey)

        Dim pdfpath As String = Me.CarriersBO1.PDFFormPath
        Dim sb As StringBuilder = New StringBuilder
        Dim sb2 As StringBuilder = New StringBuilder
        Dim sb3 As StringBuilder = New StringBuilder
        Dim pdffields As String

        For Each pdffile As String In Directory.GetFiles(pdfpath, "*.pdf")

            sb.Append(pdffile).AppendLine()
            sb.AppendLine()

            pdffields = GetPDFFormFields(pdffile)
            sb.Append(pdffields).AppendLine()
            sb2.Append(pdffields).AppendLine()

        Next

        Dim fldsstr As String = sb2.ToString

        Dim allfields As String()


        Dim fieldlist As List(Of String) = New List(Of String)


        allfields = fldsstr.Split(New String() {ControlChars.NewLine, ",", ";"}, StringSplitOptions.RemoveEmptyEntries)


        For Each fld As String In allfields
            If Not fieldlist.Contains(fld) Then
                fieldlist.Add(fld)
            End If
        Next

        fieldlist.Sort()
        fieldlist = fieldlist.Distinct().ToList()

        For Each fld In fieldlist
            sb3.Append(fld.ToString).AppendLine()
        Next

        fldsstr = sb3.ToString

        Dim myWriter As StreamWriter
        Dim mywriter2 As StreamWriter
        Dim myStream As FileStream
        Dim mystream2 As FileStream
        Dim outfile As String = Path.Combine(Me.CarriersBO1.PDFFormPath, Me.CarriersBO1.Carrier & "fieldsbyform.txt")
        Dim fldlist As String = Path.Combine(Me.CarriersBO1.PDFFormPath, Me.CarriersBO1.Carrier & "DistinctFields.txt")

        myStream = New FileStream(outfile, FileMode.Create)
        myWriter = New StreamWriter(myStream)

        myWriter.Write(sb.ToString)

        myWriter.Close()
        myStream.Close()

        mystream2 = New FileStream(fldlist, FileMode.Create)
        mywriter2 = New StreamWriter(mystream2)

        mywriter2.Write(fldsstr)

        mywriter2.Close()
        mystream2.Close()

        Process.Start(outfile)
        Process.Start(fldlist)

    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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform