如何使用c#从pdf中提取特定文本的控件属性 [英] How do I extract control attributes of specific text from pdf using c#

查看:107
本文介绍了如何使用c#从pdf中提取特定文本的控件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有pdf文件,我需要提取特定文本(例如:发票号)控制属性,就像其他RPA工具一样

I have pdf files from which I need to extract specific text(ex: invoice no) control attributes like other RPA tools do 

EX:  < wnd app ='acrord32.exe'
cls ='AcrobatSDIWindow'
title ='invoice3.pdf - Adob​​e Acrobat Reader DC' />


< wnd cls ='AVL_AVView'
title ='AVPageView' / >


< ctrl idx ='1'
角色 ='row' />

< ctrl name ='发票编号:AT-30411567   '
角色 ='文字' />

EX: <wnd app='acrord32.exe' cls='AcrobatSDIWindow' title='invoice3.pdf - Adobe Acrobat Reader DC' />
<wnd cls='AVL_AVView' title='AVPageView' />
<ctrl idx='1' role='row' />
<ctrl name='Invoice Number: AT-30411567   ' role='text' />

有谁知道请帮我解决这个问题

Is anyone knows please help me to solve this

推荐答案



您好Sunitha_Bist,


Hi Sunitha_Bist,

>>如何提取控件来自pdf的特定文本的属性使用c#

您可以使用 ITextSharp
从PDF文档中提取纯文本。

You can use ITextSharp to extract plain text from PDF documents.

以下代码供您参考。

            string TempsaveFilename = @"D:\hello2.pdf";
            PdfReader pdfReader = new PdfReader(@"D:\hello.pdf");
            PdfStamper stamper = new PdfStamper(pdfReader, new FileStream(TempsaveFilename, FileMode.Create), '\0', true);
            AcroFields fields = stamper.AcroFields;
            AcroFields pdfFormFields = pdfReader.AcroFields;
            foreach (KeyValuePair<string, AcroFields.Item> kvp in fields.Fields)
            {
                string FieldValue = "a";
                if (FieldValue != "")
                {
                    //var oldvalue = pdfReader.AcroFields.GetField(kvp.Key);
                    fields.SetField(kvp.Key, FieldValue);
                }
            }

            stamper.FormFlattening = false;
            stamper.Close();
            pdfReader.Close();



以下文章供您参考。


The following articles for your reference.

使用iTextSharp阅读PDF表单字段:

https://community.dynamics.com/crm/b/crmmitchmilam/archive/2012/11/14/reading-pdf-form-fields-using-itextsharp

Reading PDF form fields using iTextSharp:
https://community.dynamics.com/crm/b/crmmitchmilam/archive/2012/11/14/reading-pdf-form-fields-using-itextsharp

用C#(100%.NET)从PDF中提取文本:

https://www.codeproject.com/Articles/14170/Extract-Text-from-PDF-in-C-NET

Extract Text from PDF in C# (100% .NET):
https://www.codeproject.com/Articles/14170/Extract-Text-from-PDF-in-C-NET



最好的问候,


Best Regards,

Yohann Lu

Yohann Lu


这篇关于如何使用c#从pdf中提取特定文本的控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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