严重性 代码 说明 项目 文件 行 禁止显示状态 错误 CS1061 “PdfAcroForm”未包含“GetFormFields”的定义,并且找不到可接受第一个“PdfAcroForm”类型参数的可访问扩展方法“GetFormFields”(是否缺少 using 指令或程序集引用?) IText7Library E:\Study\Pragram\C#\PDF\PDFStudio\IText7Library\PDFHelp\TableAnalyzer.cs 26 活动
时间: 2023-07-21 08:38:33 浏览: 43
这个错误发生在使用 iText7 的 PdfAcroForm 类时,因为 PdfAcroForm 类中没有 GetFormFields() 方法。
如果你想获取 PDF 表单字段,可以使用 PdfDocument 类中的 GetFormFields() 方法,如下所示:
```
PdfDocument pdfDocument = new PdfDocument(new PdfReader("path/to/pdf/file"));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, true);
if (form != null) {
IDictionary<String, PdfFormField> fields = form.GetFormFields();
foreach (String fieldName in fields.Keys) {
// Do something with the field name
}
}
pdfDocument.Close();
```
这里,我们首先使用 PdfDocument 打开 PDF 文件,并获取 PdfAcroForm 对象。然后,我们检查表单是否存在,如果存在,就使用 GetFormFields() 方法获取表单字段。
如果你想继续使用 PdfReader 类并获取 PDF 表单字段,可以使用 PdfAcroFields 类,如下所示:
```
PdfReader pdfReader = new PdfReader("path/to/pdf/file");
PdfDocument pdfDocument = new PdfDocument(pdfReader);
PdfAcroFields form = PdfAcroFields.GetAcroFields(pdfDocument, true);
if (form != null) {
IDictionary<String, AcroFields.Item> fields = form.Fields;
foreach (String fieldName in fields.Keys) {
// Do something with the field name
}
}
pdfDocument.Close();
```
这里,我们首先使用 PdfReader 打开 PDF 文件,并获取 PdfDocument 对象。然后,我们使用 PdfAcroFields 类获取表单字段。