阅读.pdf控件中的文本 [英] read texts in .pdf controls

查看:81
本文介绍了阅读.pdf控件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的目标是阅读.pdf文件中控件内的文本...
我正在使用iTextSharp参考...
下面的C#代码仅读取文本(最初在文件中键入),而不读取控件中键入的文本.
你知道如何解决这个问题吗?

谢谢

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

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;

        }

推荐答案




Hi,


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





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



希望它对您有用.

问候



Hope it works for you.

Regards


这篇关于阅读.pdf控件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆