[jira] [Commented] (PDFBOX-2617) Group of Button fields treated as a Radio Button group
[ https://issues.apache.org/jira/browse/PDFBOX-2617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14742060#comment-14742060 ] Ilya Sazonov commented on PDFBOX-2617: -- Here's how I used to collect possible values for a group of checkboxes before 1.8.9 . To continue using this code I have to check if checkbox has kids and if it does - convert it to PDRadioButton public List getValuesWithWorkaround(PDField group) { try { List fieldValues = new ArrayList(); List kids = group.getKids(); for (int i = 0;kids != null && i < kids.size(); i++) { COSObjectable kid = kids.get(i); if (kid instanceof PDCheckbox) { if (!fieldValues.contains(((PDCheckbox) kid).getOnValue())) { fieldValues.add(((PDCheckbox) kid).getOnValue()); } } } return fieldValues; } catch(IOException e) { throw new RuntimeException("trouble getting values"); } } And here's how I have to do it now private static final COSName KEY = COSName.getPDFName("AS"); private static final COSName OFF_VALUE = COSName.getPDFName("Off"); public List getValues(PDCheckbox checbox) { try { List fieldValues = new ArrayList(); List kids = checbox.getKids(); List widgets = new ArrayList(); for (int i = 0;kids != null && i < kids.size(); i++) { COSObjectable kid = kids.get(i); if (kid instanceof PDAnnotationWidget) { widgets.add((PDAnnotationWidget) kid); } } for (PDAnnotationWidget widget : widgets) { COSDictionary ap = (COSDictionary) widget.getDictionary().getDictionaryObject(COSName.getPDFName("AP")); widget.getDictionary().setItem(KEY, COSName.getPDFName("Yes")); COSBase n = ap.getDictionaryObject(COSName.getPDFName("N")); //N can be a COSDictionary or a COSStream if( n instanceof COSDictionary ) { for( COSName key :((COSDictionary)n).keySet() ) { if( !key.equals( OFF_VALUE) ) { String onValue = key.getName(); if (!fieldValues.contains(onValue)) fieldValues.add(onValue); } } } } return fieldValues; } catch(IOException e) { throw new RuntimeException("trouble getting values"); } } Please note, that KEY and OFF_VALUE are originally static private fields for checkbox and I think this code should be a part of of PDCheckbox class. And PDCheckbox doesn't have such methods even in 2.0. It look like 2.0 treats checkbox as a single entity with single value, which is wrong. I have made a demo project with a class which has 2 methods and unit test. > Group of Button fields treated as a Radio Button group > -- > > Key: PDFBOX-2617 > URL: https://issues.apache.org/jira/browse/PDFBOX-2617 > Project: PDFBox > Issue Type: Bug > Components: AcroForm >Affects Versions: 1.8.8, 2.0.0 > Environment: Windows 7, Eclipse, JRE 1.8.0_25 >Reporter: Gilad Denneboom >Assignee: Maruan Sahyoun >Priority: Minor > Fix For: 1.8.9, 2.0.0 > > Attachments: test.pdf > > > When creating a group of identical button fields PDFBox reads them as a group > of radio-button fields, with each widget as a check-box, which is incorrect. > The main field has the class PDRadioCollection and each kid is a PDCheckbox. > Run the following code on the attached file: > PDDocument doc = PDDocument.load( new File("test.pdf") ); > PDAcroForm form = doc.getDocumentCatalog().getAcroForm(); > List fields = form.getFields(); > for (PDField f: fields) { > System.out.println("Name:" + f.getFullyQualifiedName()); > System.out.println("Type:" + f.getFieldType()); > System.out.println("Class:" + f.getClass()); > List kids = f.getKids(); > if (kids!=null) { > for (COSObjectable c : kids) { > System.out.println("Kid Class: " + c.getClass()); > > } > > } > } > The results are: > Name:Test > Type:Btn > Class:class org.apache.pdfbox.pdmodel.interactive.form.PDRadioCollection > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail:
[jira] [Commented] (PDFBOX-2617) Group of Button fields treated as a Radio Button group
[ https://issues.apache.org/jira/browse/PDFBOX-2617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14742061#comment-14742061 ] Ilya Sazonov commented on PDFBOX-2617: -- I've made a demo project to describe the problem, but it looks like I can't upload it here. Where do I send it? > Group of Button fields treated as a Radio Button group > -- > > Key: PDFBOX-2617 > URL: https://issues.apache.org/jira/browse/PDFBOX-2617 > Project: PDFBox > Issue Type: Bug > Components: AcroForm >Affects Versions: 1.8.8, 2.0.0 > Environment: Windows 7, Eclipse, JRE 1.8.0_25 >Reporter: Gilad Denneboom >Assignee: Maruan Sahyoun >Priority: Minor > Fix For: 1.8.9, 2.0.0 > > Attachments: test.pdf > > > When creating a group of identical button fields PDFBox reads them as a group > of radio-button fields, with each widget as a check-box, which is incorrect. > The main field has the class PDRadioCollection and each kid is a PDCheckbox. > Run the following code on the attached file: > PDDocument doc = PDDocument.load( new File("test.pdf") ); > PDAcroForm form = doc.getDocumentCatalog().getAcroForm(); > List fields = form.getFields(); > for (PDField f: fields) { > System.out.println("Name:" + f.getFullyQualifiedName()); > System.out.println("Type:" + f.getFieldType()); > System.out.println("Class:" + f.getClass()); > List kids = f.getKids(); > if (kids!=null) { > for (COSObjectable c : kids) { > System.out.println("Kid Class: " + c.getClass()); > > } > > } > } > The results are: > Name:Test > Type:Btn > Class:class org.apache.pdfbox.pdmodel.interactive.form.PDRadioCollection > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org
[jira] [Commented] (PDFBOX-2617) Group of Button fields treated as a Radio Button group
[ https://issues.apache.org/jira/browse/PDFBOX-2617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14736990#comment-14736990 ] Ilya Sazonov commented on PDFBOX-2617: -- All code, that was relying on treating checkbox with kids as radio collection is broken now. Introducing breaking changes in major release is ok, but doing it with a bugfix is questionable. I understand, that, according to pdf specs, existing behaviour was incorrect, and it had to be fixed. But it was there for years and a lot of code depends on it. Refreshing library to a new patch version is supposed to be safe, it isn't supposed to break user code. I think putting it to 1.8 wasn't a right thing to do. Think of all the people, who have refreshed pdfbox to a new version, which has changed the way their code worked without warning. Maybe you should revert this bugfix for 1.8 and leave it in 2.0 only. > Group of Button fields treated as a Radio Button group > -- > > Key: PDFBOX-2617 > URL: https://issues.apache.org/jira/browse/PDFBOX-2617 > Project: PDFBox > Issue Type: Bug > Components: AcroForm >Affects Versions: 1.8.8, 2.0.0 > Environment: Windows 7, Eclipse, JRE 1.8.0_25 >Reporter: Gilad Denneboom >Assignee: Maruan Sahyoun >Priority: Minor > Fix For: 1.8.9, 2.0.0 > > Attachments: test.pdf > > > When creating a group of identical button fields PDFBox reads them as a group > of radio-button fields, with each widget as a check-box, which is incorrect. > The main field has the class PDRadioCollection and each kid is a PDCheckbox. > Run the following code on the attached file: > PDDocument doc = PDDocument.load( new File("test.pdf") ); > PDAcroForm form = doc.getDocumentCatalog().getAcroForm(); > List fields = form.getFields(); > for (PDField f: fields) { > System.out.println("Name:" + f.getFullyQualifiedName()); > System.out.println("Type:" + f.getFieldType()); > System.out.println("Class:" + f.getClass()); > List kids = f.getKids(); > if (kids!=null) { > for (COSObjectable c : kids) { > System.out.println("Kid Class: " + c.getClass()); > > } > > } > } > The results are: > Name:Test > Type:Btn > Class:class org.apache.pdfbox.pdmodel.interactive.form.PDRadioCollection > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org
[jira] [Commented] (PDFBOX-2617) Group of Button fields treated as a Radio Button group
[ https://issues.apache.org/jira/browse/PDFBOX-2617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=14737141#comment-14737141 ] Ilya Sazonov commented on PDFBOX-2617: -- I have refreshed pdfbox from 1.8.6 to 1.8.9 and it made 3 of my tests fail. So it wasn't a big deal for me, I have already worked around the issue by checking if PDCheckbox has kids and converting it to PDRadioCollection if it does. I know a workaround is not a nice way of doing things, but I'm planning to wait till 2.0 is released and then doing it properly. Don't worry about me, I got it covered :). But introducing breaking changes with a patch is still not a nice thing to do. Changing the way how terminal fields are recognized in pdfbox seems pretty big to me. Totally worth of increasing minor version at least. Yes, a half of a year has passed and I'm the only guy complaining, so maybe it's ok this time, but I don't want to meet something similar in the future. I want to trust pdfbox, that's what I want to say :). Also I honestly don't see how the changes https://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java?r1=1654480=1654479=1654480;>here help with multiple occurrences of the same field in a pdf. But I understand I either have to make that workaround, or write code to walk through widget dictionaries and retrieve field values. If library has replaced PDRadioCollection with PDCheckbox, then PDCheckbox should have a method to get it's possible values, but it doesn't. Even in 2.0 . So, thank you for your answer, and please don't take my complaints personally, I'm not Linus Torvalds you know :). And if I'm wrong about having to retrieve field values manually, please correct me. It would be nice to know there's a nice way of doing it. If I wasn't clear about what I wanted and you want code, I can send it to you a little bit later. > Group of Button fields treated as a Radio Button group > -- > > Key: PDFBOX-2617 > URL: https://issues.apache.org/jira/browse/PDFBOX-2617 > Project: PDFBox > Issue Type: Bug > Components: AcroForm >Affects Versions: 1.8.8, 2.0.0 > Environment: Windows 7, Eclipse, JRE 1.8.0_25 >Reporter: Gilad Denneboom >Assignee: Maruan Sahyoun >Priority: Minor > Fix For: 1.8.9, 2.0.0 > > Attachments: test.pdf > > > When creating a group of identical button fields PDFBox reads them as a group > of radio-button fields, with each widget as a check-box, which is incorrect. > The main field has the class PDRadioCollection and each kid is a PDCheckbox. > Run the following code on the attached file: > PDDocument doc = PDDocument.load( new File("test.pdf") ); > PDAcroForm form = doc.getDocumentCatalog().getAcroForm(); > List fields = form.getFields(); > for (PDField f: fields) { > System.out.println("Name:" + f.getFullyQualifiedName()); > System.out.println("Type:" + f.getFieldType()); > System.out.println("Class:" + f.getClass()); > List kids = f.getKids(); > if (kids!=null) { > for (COSObjectable c : kids) { > System.out.println("Kid Class: " + c.getClass()); > > } > > } > } > The results are: > Name:Test > Type:Btn > Class:class org.apache.pdfbox.pdmodel.interactive.form.PDRadioCollection > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox > Kid Class: class org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org