Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,
My goal is to read the texts inside the controls in the .pdf file...
I am using the iTextSharp reference...
The C# code below only reads the texts (Initially typed in the file) but NOT the texts typed in the controls.
Do you know how to solve this please?

Thanks

C#
private void button2_Click(object sender, EventArgs e)
        {
            string strText = string.Empty;
            string filename = @"C:\pdfTestFile.pdf";
            PdfReader pdfReader = new PdfReader(filename);
            for (int nPage = 1; nPage <= pdfReader.NumberOfPages; nPage++)
            {
                ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
                PdfReader reader2 = new PdfReader(filename);
                String s = PdfTextExtractor.GetTextFromPage(reader2, nPage, its);

                s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
                strText = strText + s;
                reader2.Close();
            }

            string strInput = strText;

        }
Posted

1 solution

Hi,


C#
PdfReader myReader = new PdfReader(@"c:\test.pdf");
AcroFields myFields = myReader.AcroFields;


C#
foreach(KeyValuePair<string,iTextSharp.text.pdf.AcroFields.Item> pair in myFields.Fields)
           {
               MessageBox.Show(pair.Value + " " + pair.Key);
           }


Hope it works for you.

Regards
 
Share this answer
 
v2
Comments
arkiboys 22-Mar-12 6:22am    
Hi,
There is an error with red line under pdfReader.AcroFields.Fields
It gives the error message as follows:
Cannot implicitly convert type 'System.Collections.Generic.IDictionary<string,itextsharp.text.pdf.acrofields.item>' to 'iTextSharp.text.pdf.AcroFields'. An explicit conversion exists (are you missing a cast?
El_Codero 22-Mar-12 8:39am    
Hi,
oh, seems something changed in iTextSharp library since my version,sorry for this.
Updated my solution.
With Best Regards
El_Codero 23-Mar-12 21:28pm    
Could you please considering about accepting my answer? It's a sign for other users that solution works. Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900