ItextSharp - Acrofields是空的 [英] ItextSharp - Acrofields are empty
本文介绍了ItextSharp - Acrofields是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个填写完整字段的PDF表单。如果我尝试阅读acrofields它们是空的。但在PDF中我可以更改值并保存它们。
I have a PDF form with filled out fields. If I try to read the acrofields they are empty. But in the PDF I can change the values and save them.
private static string GetFormFieldNamesWithValues(PdfReader pdfReader)
{
return string.Join("\r\n", pdfReader.AcroFields.Fields
.Select(x => x.Key + "=" +
pdfReader.AcroFields.GetField(x.Key))
.ToArray());
}
var reader = new PdfReader((DataContext as PDFContext).Datei);
AcroFields form = reader.AcroFields;
txt.Text = GetFormFieldNamesWithValues(reader);
如何阅读字段?
推荐答案
显然您的PDF已损坏。这些字段在页面级别定义为小部件注释,但在文档中设置的 / AcroForm
字段中未引用它们根级别。
Clearly your PDF is broken. The fields are defined as widget annotations on the page level, but they aren't referenced in the /AcroForm
fields set on the document root level.
您可以使用 FixBrokenForm 代码示例:
PdfReader reader = new PdfReader(src);
PdfDictionary root = reader.getCatalog();
PdfDictionary form = root.getAsDict(PdfName.ACROFORM);
PdfArray fields = form.getAsArray(PdfName.FIELDS);
PdfDictionary page;
PdfArray annots;
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
page = reader.getPageN(i);
annots = page.getAsArray(PdfName.ANNOTS);
for (int j = 0; j < annots.size(); j++) {
fields.add(annots.getAsIndirectObject(j));
}
}
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.close();
reader.close();
您应该告知创建者用于生成表格的工具,他们的PDF不是符合PDF参考。
You should inform the creators of the tool that was used to produce the form that their PDFs aren't compliant with the PDF reference.
这篇关于ItextSharp - Acrofields是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文