Java iText and custom Radiobutton behaviour

霸气de小男生 提交于 2019-12-24 09:48:41

问题


I am using iText 2.1.7. I have three radiobuttons in a table cell.

Initial all buttons (b1, b2 and b3) are unchecked.

Desired behaviour:

If Check b1: b2 & b3 to uncheck

If Check b2: b1 to uncheck

If Check b3: b1 to uncheck

So b2 and b3 can be checked at the same time.

Additionally i want that all buttons can be toggled to off again.

How can i achieve that behaviour? Help appreciated!


回答1:


Before I fully answer your question have a look a the example behavior - is that what you want? Do you have an PDF with existing fields or do you want to newly add those fields?

The solution does not use javascript.

1. Create a checkbox with 3 kids
1 0 obj
<</DA(/ZaDb 0 Tf 0 g)/FT/Btn/Kids[14 0 R 19 0 R 24 0 R]/T(checkbox1)>>
endobj

2. Create the 3 kids with values 1xb1 and 2xb2
14 0 obj
<</AP<</b1 18 0 R>>/N<</Off 15 0 R/b1 16 0 R>>>>/AS/Off/F 4/MK<</CA(8)>>/P 12 0 R/Parent 1 0 R/Rect[122 723 140 740]/Subtype/Widget/Type/Annot>>
endobj

19 0 obj
<</AP<</b2 23 0 R>>/N<</Off 20 0 R/b2 21 0 R>>>>/AS/Off/F 4/MK<</CA(8)>>/P 12 0 R/Parent 1 0 R/Rect[145 722 162 739]/Subtype/Widget/Type/Annot>>
endobj

24 0 obj
<</AP<</b2 28 0 R>>/N<</Off 25 0 R/b2 26 0 R>>>>/AS/Off/F 4/MK<</CA(8)>>/P 12 0 R/Parent 1 0 R/Rect[167 721 185 738]/Subtype/Widget/Type/Annot>>
endobj

Update: You can find the solution how to completely add new checkoxes to a PDF here.



来源:https://stackoverflow.com/questions/47351203/java-itext-and-custom-radiobutton-behaviour

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!