You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Itext 7.0读取PDF Acroforms字段为空问题求助

iText 7读取特定PDF表单字段返回空值的解决方法
  • 存在一个已填充字段的PDF表单(dnd-character.pdf),使用iText 7.0读取其AcroFields时返回空值,但该PDF中的字段可正常修改并保存值
  • 现有代码能正常读取其他PDF表单(如PDF2),但读取此目标PDF时完全失效
  • 尝试旧方案PdfArray fields = form.GetAsArray(PdfName.Fields);触发NullReferenceException,已确认目标PDF非XFA表单
  • 通过RUPS对比PDF层级结构,发现目标PDF的表单字段组织方式与正常PDF不同,现寻求读取该PDF表单字段值(如/V对应内容)的解决方法

测试代码如下:

namespace Tutorial {
    public class FillForm {
        public const String SRC = "../../../resources/pdf/dnd-character.pdf";
        public const String DEST = "../../../results/fill_dnd.pdf";

        public static void Main(String[] args) {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new FillForm().ManipulatePdf(SRC, DEST);
        }

        public virtual void ManipulatePdf(String src, String dest) {
            PdfDocument pdf = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
            PdfAcroForm form = PdfFormCreator.GetAcroForm(pdf, true);
            IDictionary<String, PdfFormField> fields = form.GetAllFormFields();
            Console.WriteLine(fields.Count);
            foreach(KeyValuePair<string, PdfFormField> entry in fields)
            {
                Console.WriteLine(entry.Key);
            }
            pdf.Close();
        }
    }
}

内容的提问来源于stack exchange,提问作者Jesse Hamlin-Navias

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 02:35:07