用iText7填充pdf检查字段

古斯塔沃·萨贝尔

我正在尝试使用iText7在PDF上选中一个复选框。但是,不仅检查一个字段,还检查所有字段

我需要的:

img

我得到的是:

img

编辑时的PDF:

img

我认为出口价值与之有关。但是我不知道该怎么办。

img

我的代码:

private static void CreatePdf(string output)
{
    using var _pdfDoc = new PdfDocument(new PdfReader("CheckTest.pdf"), new PdfWriter(output));
    var form = PdfAcroForm.GetAcroForm(_pdfDoc, true);
    var check = form.GetField("Check");
    check.SetValue("01");
}

PDF:链接

有人知道如何正确检查吗?

谢谢!

mkl

首先,PDF实质上将PDF AcroForm复选框字段误用作单选按钮,而不是使用真正的PDF AcroForm单选按钮字段。

The PDF specification does not clearly specify what a PDF viewer should do in such a case (it's mis-use after all) but the developers of the PDF form generator in question probably have experimented and determined that in the most widely used PDF viewer, Adobe Acrobat Reader, this mis-use works just as they want.

As this use is beyond specification, though, other PDF processors processing such PDFs may produce completely different results without doing anything wrong.


That being said, there is a way to fill the form using iText and achieve results similar to those generated by Adobe Reader.

The problem at hand is that iText by default for all form field types except actual AcroForm radio button fields generates new appearances in a way appropriate for the field type when setting the field value. In your document there are three check box field objects with the same name. Thus, they are considered a single check box with three widgets representing the same value, and so the appearances are generated as you observe.

But you can tell iText to not generate new appearances, using another SetValue overload accepting an additional boolean value, simply replace

check.SetValue("01");

by

check.SetValue("01", false);

Now iText makes do with the existing appearances, so only the field becomes checked that has an appearance for that "01" value.

当心,仅在这种情况下才能阻止iText生成外观。例如,在文本字段的情况下,即使内部字段值已更改,不更新外观也会导致具有旧字段内容的旧外观继续显示。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

用汉字填充pdf字段乱码

来自分类Dev

是检查相对值的检查字段

来自分类Dev

如何检查字段是否唯一

来自分类Dev

pdf表单字段在Android上用itext填充后为空

来自分类Dev

iText7以错误的顺序读出行

来自分类Dev

使用iText7和Vb.Net签名Pdf时缺少MissingMethodException

来自分类Dev

如何使用iText7将.p7s字节数组插入PDF?

来自分类Dev

通过后期请求接受Pdf并传递给C#.net Core中的itext7 pdfreader

来自分类Dev

如何在itext7 html到pdf转换器的converterproperties中设置baseuri

来自分类Dev

在iText7(.NET)中将页脚添加到现有PDF的每一页

来自分类Dev

iText7(.net)SignExternalSignatureContainer NullReferenceException

来自分类Dev

如何使用itext7从标记的pdf中的结构元素中提取文本

来自分类Dev

使用itext7的addind文本

来自分类Dev

iText7 PDF可以正确呈现,但在Adobe Reader中打印不正确

来自分类Dev

我如何使用itext7从存储在Blob存储中的pdf中提取文本?

来自分类Dev

iText7延迟签名的pdf文档显示“自应用签名以来,该文档已被更改或损坏”

来自分类Dev

检查字段是否被编辑?

来自分类Dev

如何检查字段“选择”?

来自分类Dev

在IText7中创建PdfFont

来自分类Dev

在pdf文档itext7中获取所有acrosfields的可用信息

来自分类Dev

iText7 Java添加文本问题

来自分类Dev

使用 IText7 将 SVG 图像添加到 PDF

来自分类Dev

iText7 - 如何设置 LoggerFactory?

来自分类Dev

iText7 无法设置日志

来自分类Dev

iText7 目录

来自分类Dev

Itext7 pdf.version.not.valid

来自分类Dev

如何使用 IText7 和 C# 在现有 PDF 中的内部链接下划线?

来自分类Dev

iText7 setRotation() 无法正常工作

来自分类Dev

iText7 图像透明度

Related 相关文章

热门标签

归档