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

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

问题描述

我想知道是否可以使用 iTextSharp 读取 PDF 表单数据(填写并与表单一起保存的表单).我该怎么做?

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?

推荐答案

您必须在 PDF 表单中找出字段名称.获取字段,然后读取它们的值.

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");

显然在上面的代码中,字段名称是 PDF 表单字段的名称,GetField 方法返回该值的字符串表示形式.这里是一篇文章,其中包含您可能会使用的示例代码.它展示了如何使用 iTextSharp 读取和写入表单字段.

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天全站免登陆