如何使用iTextSharp阅读PDF表格数据? [英] How to read PDF form data using iTextSharp?

查看:303
本文介绍了如何使用iTextSharp阅读PDF表格数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出是否可以使用iTextSharp读取PDF表格数据(表格填入并保存在表格中)。我怎么做到这一点?

解决方案

您必须在PDF表单中找到字段名称。获取字段,然后读取其值。


PdfReader pdfReader = new PdfReader(pdfTemplate);
AcroFields fields = pdfReader.AcroFields.Fields;
string val = fields.GetField(fieldname);

显然,在上面的代码中,字段名称是PDF表单字段的名称,GetField方法返回该值的字符串表示形式。
这里是一个带有示例代码的文章,可能可以使用。它展示了如何使用iTextSharp来读写表单字段。


I am trying to find out if it is possible to read PDF Form data (Forms filled in and saved with the form) using iTextSharp. How can I do this?

解决方案

You would have to find out the field names in the PDF form. Get the fields and then read their value.

string pdfTemplate = "my.pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
AcroFields fields = pdfReader.AcroFields.Fields;
string val = fields.GetField("fieldname");

Obviously in the code above, field name is the name of the PDF form field and the GetField method returns a string representation of that value. Here is an article with example code that you could probably use. It shows how you can both read and write form fields using iTextSharp.

这篇关于如何使用iTextSharp阅读PDF表格数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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