Hi, > Am 28.03.2016 um 22:51 schrieb Wojack, Robert (USTP) > <[email protected]>: > > Thanks Maruan! > > However, when try to use the code, I get an exception in line 4th line: > > Exception in thread "main" java.lang.ClassCastException: > org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox cannot be cast to > org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget > > As a reminder, I'm using PDFBox 1.8.8 if that matters. In the meantime, I'll > play around with what you provided and see if I can get it to work.
yes, that matters - my code worked with 1.8.11. The fact that a widget annotation was treated as a checkbox in 1.8.8 (and earlier) was a bug which has been resolved in 1.8.9 onwards. See PDFBOX-2617 BR Maruan > > > > -----Original Message----- > From: Maruan Sahyoun [mailto:[email protected]] > Sent: Monday, March 28, 2016 3:30 PM > To: [email protected] > Subject: Re: How to bind distinct OnValues for checkbox group? > > Hi, > > here you go. > > > PDDocument document = PDDocument.load("form_b122a-2.pdf"); > PDAcroForm form = document.getDocumentCatalog().getAcroForm(); > PDField field = form.getField("CheckBox16"); > PDAnnotationWidget widget = (PDAnnotationWidget) > field.getKids().get(1); > > // get the fields normal appearances i.e. the options to be > selected > Map<String,PDAppearanceStream> normalAppearances = > widget.getAppearance().getNormalAppearance(); > > // Print out the current entries. There are two options > // On and Off > System.out.println(normalAppearances); > > // Add a new entry with the desired value copying over the > // appearance stream of the to be 'renamed' entry > normalAppearances.put("Yes",normalAppearances.get("On")); > normalAppearances.remove("On"); > > // Print out the new entries. There are two options > // Yes and Off > System.out.println(normalAppearances); > > document.save("form_b122a-2-pdfbox.pdf"); > document.close(); > > > BR > Maruan > >> Am 28.03.2016 um 15:14 schrieb Wojack, Robert (USTP) >> <[email protected]>: >> >> Yes. It is a publicly available PDF: >> >> http://www.uscourts.gov/file/18792/download >> >> >> Go to the last page (pg9) and click the No/Yes checkboxes for line 43. You >> will see the behavior where each box is checked or unchecked regardless of >> which one is actually clicked. >> >> Thanks in advance for taking a look at this. >> >> >> >> >> >> -----Original Message----- >> From: Maruan Sahyoun [mailto:[email protected]] >> Sent: Saturday, March 26, 2016 7:58 AM >> To: [email protected] >> Subject: Re: How to bind distinct OnValues for checkbox group? >> >> Hi, >> >> is it possible to share the PDF? >> >> BR >> Maruan >> >>> Am 25.03.2016 um 19:02 schrieb Wojack, Robert (USTP) >>> <[email protected]>: >>> >>> They are two distinct checkboxes within a radio collection. The problem is >>> they both have their onValue set to "On". I need to set the onValue for one >>> of them to something else ("Off"). >>> >>> Your code has given me some ideas, but so far, I haven't been able to >>> adequately solve it. >>> >>> Thanks, >>> >>> Bob >>> >>> -----Original Message----- >>> From: Maruan Sahyoun [mailto:[email protected]] >>> Sent: Thursday, March 24, 2016 6:16 AM >>> To: [email protected] >>> Subject: Re: How to bind distinct OnValues for checkbox group? >>> >>> Hi, >>> >>> are you sure that these are two distinct fields? If yes, you can set >>> the On value - using 1.8.x - with >>> >>> PDAnnotationWidget widget = field.getWidget() PDAppearanceDictionary >>> apDictionary = widget.getAppearance(); PDAppearanceEntry >>> normalAppearance = apDictionary.getNormalAppearance(); >>> >>> // to get the current values >>> Map<String,PDAppearanceStream> appearanceMap = >>> apDictionary.getNormalAppearance(); >>> >>> // to set the values >>> apDictionary.setNormalAppearance(Map<String,PDAppearanceStream>); >>> >>> >>> Haven't tested that code but should give you an idea. >>> >>> BR >>> Maruan >>> >>> >>> >>>> Am 23.03.2016 um 16:51 schrieb Wojack, Robert (USTP) >>>> <[email protected]>: >>>> >>>> We have a client that provides us with interactive PDF forms for our app >>>> to populate fields with user data. The problem is the client sometimes >>>> provides us forms with typos and mistakes and is not responsive about >>>> fixing them. >>>> >>>> In this case, we are given an interactive PDF form that has a pair of >>>> Yes/No checkboxes. Unfortunately, when creating the PDF, the client bound >>>> both checkboxes to the same "On" value. As a result, when a user checks a >>>> box, both of them get checked (additionally, when a user unchecks a box, >>>> they both become unchecked). >>>> >>>> I can use PDFBox to open the file, find the PDCheckbox object in question >>>> and list their On and Off values, but I can't figure out how to update the >>>> bindings to distinct values. Is it possible to do this in PDFBox? If so, >>>> can someone please provide some guidance? >>>> >>>> We are using PDFBox 1.8.8. We are not positioned to upgrade to 2.0.0. >>>> >>>> Thanks >>>> >>>> >>>> Bob Wojack >>>> CSRA International, Inc. >>>> Onsite Contractor for the Department of Justice Senior Tech Lead US >>>> Trustee Program >>>> Onsite Email Address: >>>> [email protected]<mailto:[email protected]> >>>> Onsite Phone Number: TBD >>>> Cell#: (301)910-9975 >>>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [email protected] >>> For additional commands, e-mail: [email protected] >>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [email protected] >>> For additional commands, e-mail: [email protected] >>> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

