简体   繁体   English

更改iText中复选框字段的外观

[英]Changing the appearance of a checkbox field in iText

I need to be able to customize the checkbox fill type on demand as I render the pdf. 我需要能够在渲染pdf时根据需要自定义复选框填充类型。

I must do this only with the AcroFields (pdfStamper.getAcroFields()), because I'm not creating any new fields (just modifying), and that's the only thing I have available to me in scope. 我必须只使用AcroFields (pdfStamper.getAcroFields()),因为我没有创建任何新字段(只是修改),这是我在范围内唯一可用的东西。 I have tried about a hundred things, including the one listed below, which was my best guess on how to do this. 我已经尝试了大约一百件事,包括下面列出的一件事,这是我对如何做到这一点的最好猜测。

  PdfDictionary dictionary = (PdfDictionary)  acrofields.getFieldItem("ABCD").getWidget(0).get(PdfName.MK);
  dictionary.put(PdfName.CA, new PdfString("8", PdfObject.TEXT_UNICODE));

ABCD is just for testing. ABCD仅用于测试。

I am very stuck, and any help would be greatly appreciated. 我非常困难,任何帮助都将非常感激。 I am able to change the value in the dictionary, but it does not seem to have any affect when I write the pdf to a file. 我能够更改字典中的值,但是当我将pdf写入文件时似乎没有任何影响。 Other changes such as setting the checkbox to being checked/unchecked work, as well as populating text fields. 其他更改(例如将复选框设置为选中/取消选中)以及填充文本字段。 So I as very surprised and confused why this is not working. 所以我非常惊讶和困惑为什么这不起作用。

You're trying to change the caption of a check box, but it's unclear to me what you expect to see. 您正试图更改复选框的标题,但我不清楚您希望看到的内容。 Do you want to see the text "8"? 你想看到文字“8”吗? In that case, changing the caption isn't sufficient. 在这种情况下,更改标题是不够的。 You also need to change the appearance. 您还需要更改外观。 You can find the possible appearances under the /AP key. 您可以在/AP键下找到可能的外观。 In the case of a check box, you'll find two possible appearance states under the normal appearance ( /N ). 如果是复选框,您将在正常外观( /N )下找到两种可能的外观状态。 These XObjects define what you see when the PDF is rendered. 这些XObject定义了在呈现PDF时看到的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM