You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Wojack, Robert (USTP)" <Ro...@usdoj.gov> on 2016/03/23 16:51:58 UTC

How to bind distinct OnValues for checkbox group?

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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
Onsite Phone Number:    TBD
Cell#:                              (301)910-9975


Re: How to bind distinct OnValues for checkbox group?

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 29.03.2016 um 20:04 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
> 
> We have many legacy systems using PDFBox 1.X, and there is too much PDFBox 1.X specific code that would need to change. We don't have the bandwidth to take on that refactoring at this time. :-(
> 

no worries - we can also help you while you are on 1.8.x :-) 

BR
Maruan

> 
> -----Original Message-----
> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
> Sent: Tuesday, March 29, 2016 12:40 PM
> To: users@pdfbox.apache.org
> Subject: Re: How to bind distinct OnValues for checkbox group?
> 
> Hi,
> 
>> Am 29.03.2016 um 17:01 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
>> 
>> Thanks for that info! We shall upgrade to 1.8.11
>> 
> 
> what about PDFBox 2.0.0? Dependent on what you are doing there are a lot of improvements and some new functionality:
> 
> - better parsing
> - enhancements to AcroForms
> - much better rendering
> …
> 
> BUT there might be some changes to your code necessary.
> 
> BR
> Maruan
> 
> 
>> -----Original Message-----
>> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de]
>> Sent: Tuesday, March 29, 2016 6:01 AM
>> To: users@pdfbox.apache.org
>> Subject: Re: How to bind distinct OnValues for checkbox group?
>> 
>> Hi,
>>> Am 28.03.2016 um 22:51 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
>>> 
>>> 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:sahyoun@fileaffairs.de]
>>> Sent: Monday, March 28, 2016 3:30 PM
>>> To: users@pdfbox.apache.org
>>> 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) <Ro...@usdoj.gov>:
>>>> 
>>>> 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:sahyoun@fileaffairs.de]
>>>> Sent: Saturday, March 26, 2016 7:58 AM
>>>> To: users@pdfbox.apache.org
>>>> 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) <Ro...@usdoj.gov>:
>>>>> 
>>>>> 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:sahyoun@fileaffairs.de]
>>>>> Sent: Thursday, March 24, 2016 6:16 AM
>>>>> To: users@pdfbox.apache.org
>>>>> 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) <Ro...@usdoj.gov>:
>>>>>> 
>>>>>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>>>>>> Onsite Phone Number:    TBD
>>>>>> Cell#:                              (301)910-9975
>>>>>> 
>>>>> 
>>>>> 
>>>>> -------------------------------------------------------------------
>>>>> -
>>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>> 
>>>>> 
>>>>> 
>>>>> -------------------------------------------------------------------
>>>>> -
>>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>> 
>>>> 
>>>> 
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>>> 
>>>> 
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: How to bind distinct OnValues for checkbox group?

Posted by "Wojack, Robert (USTP)" <Ro...@usdoj.gov>.
We have many legacy systems using PDFBox 1.X, and there is too much PDFBox 1.X specific code that would need to change. We don't have the bandwidth to take on that refactoring at this time. :-(


-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Tuesday, March 29, 2016 12:40 PM
To: users@pdfbox.apache.org
Subject: Re: How to bind distinct OnValues for checkbox group?

Hi,

> Am 29.03.2016 um 17:01 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
> 
> Thanks for that info! We shall upgrade to 1.8.11
> 

what about PDFBox 2.0.0? Dependent on what you are doing there are a lot of improvements and some new functionality:

- better parsing
- enhancements to AcroForms
- much better rendering
…

BUT there might be some changes to your code necessary.

BR
Maruan


> -----Original Message-----
> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de]
> Sent: Tuesday, March 29, 2016 6:01 AM
> To: users@pdfbox.apache.org
> Subject: Re: How to bind distinct OnValues for checkbox group?
> 
> Hi,
>> Am 28.03.2016 um 22:51 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
>> 
>> 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:sahyoun@fileaffairs.de]
>> Sent: Monday, March 28, 2016 3:30 PM
>> To: users@pdfbox.apache.org
>> 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) <Ro...@usdoj.gov>:
>>> 
>>> 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:sahyoun@fileaffairs.de]
>>> Sent: Saturday, March 26, 2016 7:58 AM
>>> To: users@pdfbox.apache.org
>>> 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) <Ro...@usdoj.gov>:
>>>> 
>>>> 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:sahyoun@fileaffairs.de]
>>>> Sent: Thursday, March 24, 2016 6:16 AM
>>>> To: users@pdfbox.apache.org
>>>> 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) <Ro...@usdoj.gov>:
>>>>> 
>>>>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>>>>> Onsite Phone Number:    TBD
>>>>> Cell#:                              (301)910-9975
>>>>> 
>>>> 
>>>> 
>>>> -------------------------------------------------------------------
>>>> -
>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>>> 
>>>> 
>>>> -------------------------------------------------------------------
>>>> -
>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>> 
>>> 
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>>> 
>>> 
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: How to bind distinct OnValues for checkbox group?

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 29.03.2016 um 17:01 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
> 
> Thanks for that info! We shall upgrade to 1.8.11
> 

what about PDFBox 2.0.0? Dependent on what you are doing there are a lot of improvements and some new functionality:

- better parsing
- enhancements to AcroForms
- much better rendering
…

BUT there might be some changes to your code necessary.

BR
Maruan


> -----Original Message-----
> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
> Sent: Tuesday, March 29, 2016 6:01 AM
> To: users@pdfbox.apache.org
> Subject: Re: How to bind distinct OnValues for checkbox group?
> 
> Hi,
>> Am 28.03.2016 um 22:51 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
>> 
>> 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:sahyoun@fileaffairs.de]
>> Sent: Monday, March 28, 2016 3:30 PM
>> To: users@pdfbox.apache.org
>> 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) <Ro...@usdoj.gov>:
>>> 
>>> 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:sahyoun@fileaffairs.de]
>>> Sent: Saturday, March 26, 2016 7:58 AM
>>> To: users@pdfbox.apache.org
>>> 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) <Ro...@usdoj.gov>:
>>>> 
>>>> 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:sahyoun@fileaffairs.de]
>>>> Sent: Thursday, March 24, 2016 6:16 AM
>>>> To: users@pdfbox.apache.org
>>>> 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) <Ro...@usdoj.gov>:
>>>>> 
>>>>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>>>>> Onsite Phone Number:    TBD
>>>>> Cell#:                              (301)910-9975
>>>>> 
>>>> 
>>>> 
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>>> 
>>>> 
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: How to bind distinct OnValues for checkbox group?

Posted by "Wojack, Robert (USTP)" <Ro...@usdoj.gov>.
Thanks for that info! We shall upgrade to 1.8.11

-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Tuesday, March 29, 2016 6:01 AM
To: users@pdfbox.apache.org
Subject: Re: How to bind distinct OnValues for checkbox group?

Hi,
> Am 28.03.2016 um 22:51 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
> 
> 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:sahyoun@fileaffairs.de]
> Sent: Monday, March 28, 2016 3:30 PM
> To: users@pdfbox.apache.org
> 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) <Ro...@usdoj.gov>:
>> 
>> 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:sahyoun@fileaffairs.de]
>> Sent: Saturday, March 26, 2016 7:58 AM
>> To: users@pdfbox.apache.org
>> 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) <Ro...@usdoj.gov>:
>>> 
>>> 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:sahyoun@fileaffairs.de]
>>> Sent: Thursday, March 24, 2016 6:16 AM
>>> To: users@pdfbox.apache.org
>>> 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) <Ro...@usdoj.gov>:
>>>> 
>>>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>>>> Onsite Phone Number:    TBD
>>>> Cell#:                              (301)910-9975
>>>> 
>>> 
>>> 
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>>> 
>>> 
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: How to bind distinct OnValues for checkbox group?

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,
> Am 28.03.2016 um 22:51 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
> 
> 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:sahyoun@fileaffairs.de] 
> Sent: Monday, March 28, 2016 3:30 PM
> To: users@pdfbox.apache.org
> 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) <Ro...@usdoj.gov>:
>> 
>> 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:sahyoun@fileaffairs.de]
>> Sent: Saturday, March 26, 2016 7:58 AM
>> To: users@pdfbox.apache.org
>> 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) <Ro...@usdoj.gov>:
>>> 
>>> 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:sahyoun@fileaffairs.de]
>>> Sent: Thursday, March 24, 2016 6:16 AM
>>> To: users@pdfbox.apache.org
>>> 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) <Ro...@usdoj.gov>:
>>>> 
>>>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>>>> Onsite Phone Number:    TBD
>>>> Cell#:                              (301)910-9975
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: How to bind distinct OnValues for checkbox group?

Posted by "Wojack, Robert (USTP)" <Ro...@usdoj.gov>.
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.



-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Monday, March 28, 2016 3:30 PM
To: users@pdfbox.apache.org
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) <Ro...@usdoj.gov>:
> 
> 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:sahyoun@fileaffairs.de]
> Sent: Saturday, March 26, 2016 7:58 AM
> To: users@pdfbox.apache.org
> 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) <Ro...@usdoj.gov>:
>> 
>> 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:sahyoun@fileaffairs.de]
>> Sent: Thursday, March 24, 2016 6:16 AM
>> To: users@pdfbox.apache.org
>> 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) <Ro...@usdoj.gov>:
>>> 
>>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>>> Onsite Phone Number:    TBD
>>> Cell#:                              (301)910-9975
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: How to bind distinct OnValues for checkbox group?

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
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) <Ro...@usdoj.gov>:
> 
> 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:sahyoun@fileaffairs.de] 
> Sent: Saturday, March 26, 2016 7:58 AM
> To: users@pdfbox.apache.org
> 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) <Ro...@usdoj.gov>:
>> 
>> 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:sahyoun@fileaffairs.de]
>> Sent: Thursday, March 24, 2016 6:16 AM
>> To: users@pdfbox.apache.org
>> 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) <Ro...@usdoj.gov>:
>>> 
>>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>>> Onsite Phone Number:    TBD
>>> Cell#:                              (301)910-9975
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


RE: How to bind distinct OnValues for checkbox group?

Posted by "Wojack, Robert (USTP)" <Ro...@usdoj.gov>.
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:sahyoun@fileaffairs.de] 
Sent: Saturday, March 26, 2016 7:58 AM
To: users@pdfbox.apache.org
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) <Ro...@usdoj.gov>:
> 
> 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:sahyoun@fileaffairs.de]
> Sent: Thursday, March 24, 2016 6:16 AM
> To: users@pdfbox.apache.org
> 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) <Ro...@usdoj.gov>:
>> 
>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>> Onsite Phone Number:    TBD
>> Cell#:                              (301)910-9975
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: How to bind distinct OnValues for checkbox group?

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

is it possible to share the PDF?

BR
Maruan

> Am 25.03.2016 um 19:02 schrieb Wojack, Robert (USTP) <Ro...@usdoj.gov>:
> 
> 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:sahyoun@fileaffairs.de] 
> Sent: Thursday, March 24, 2016 6:16 AM
> To: users@pdfbox.apache.org
> 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) <Ro...@usdoj.gov>:
>> 
>> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
>> Onsite Phone Number:    TBD
>> Cell#:                              (301)910-9975
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: How to bind distinct OnValues for checkbox group?

Posted by "Wojack, Robert (USTP)" <Ro...@usdoj.gov>.
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:sahyoun@fileaffairs.de] 
Sent: Thursday, March 24, 2016 6:16 AM
To: users@pdfbox.apache.org
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) <Ro...@usdoj.gov>:
> 
> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
> Onsite Phone Number:    TBD
> Cell#:                              (301)910-9975
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: How to bind distinct OnValues for checkbox group?

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
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) <Ro...@usdoj.gov>:
> 
> 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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
> Onsite Phone Number:    TBD
> Cell#:                              (301)910-9975
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: How to bind distinct OnValues for checkbox group?

Posted by "Wojack, Robert (USTP)" <Ro...@usdoj.gov>.
Thanks. However, this code looks like it will find a given checkbox (which I can already do), but I don't see any instructions that will actually update the binding.



-----Original Message-----
From: Strein, Mark C CIV USARMY TRADOC ANALYSIS CTR (US) [mailto:mark.c.strein.civ@mail.mil] 
Sent: Wednesday, March 23, 2016 12:10 PM
To: users@pdfbox.apache.org
Subject: RE: How to bind distinct OnValues for checkbox group?

Sir,

Try this:

       /**
         * Returns the PDCheckbox you want to update or check from the pdFieldList.
         * Note: One of our teams created a PDF form using 'Adobe FormsCentral developer'.
         * after interrogating the forms fields, some inconsistencies arose with checkboxes/radiobuttons.
         * 
         * Here is a name of a radio button found in the form: 
         * "VIP_KUf6k4VfAA83KYq7*XLsiA.null"
         * 
         * When it is interrogated, it will appear twice in the interrogation list as:
         * "VIP_KUf6k4VfAA83KYq7*XLsiA.null = 0"
		 * "VIP_KUf6k4VfAA83KYq7*XLsiA.null = 1"
         * 
         * To determine the state of the radiobutton you would use the form:
         * 
         * pDFFileManager.getPDCheckbox("VIP_KUf6k4VfAA83KYq7*XLsiA.null","0").isChecked()
         * 
         * @param fullyQualifiedName
         * @return - PDCheckbox or null if not found
         */
        public PDCheckbox getPDCheckbox(String fullyQualifiedName, String onValue)
        {
        	PDCheckbox checkbox = null;
            for(int i = 0; i < pdFieldList.size();i++)
            {
                PDField field = pdFieldList.get(i);
            	if(field instanceof PDCheckbox)
            	{
	                try
	                {	                    
	                    if(field.getFullyQualifiedName().equalsIgnoreCase(fullyQualifiedName) && ((PDCheckbox)field).getOnValue().equalsIgnoreCase(onValue))
	                    {
	                    	checkbox = (PDCheckbox)field;
	                        break;
	                    }
	                }
	                catch(IOException e)
	                {
	                    e.printStackTrace();
	                }
            	}
            }
            return checkbox;
        }

V/R,
Mark Strein

TRAC-FLVN
Wargaming and Simulations Directorate
Analytic Tools Division - Paving Crew
Keeper of the Codes
913-684-9309



-----Original Message-----
From: Wojack, Robert (USTP) [mailto:Robert.Wojack@usdoj.gov] 
Sent: Wednesday, March 23, 2016 10:52 AM
To: users@pdfbox.apache.org
Subject: [Non-DoD Source] How to bind distinct OnValues for checkbox group?

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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
Onsite Phone Number:    TBD
Cell#:                              (301)910-9975


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: How to bind distinct OnValues for checkbox group?

Posted by "Strein, Mark C CIV USARMY TRADOC ANALYSIS CTR (US)" <ma...@mail.mil>.
Sir,

Try this:

       /**
         * Returns the PDCheckbox you want to update or check from the pdFieldList.
         * Note: One of our teams created a PDF form using 'Adobe FormsCentral developer'.
         * after interrogating the forms fields, some inconsistencies arose with checkboxes/radiobuttons.
         * 
         * Here is a name of a radio button found in the form: 
         * "VIP_KUf6k4VfAA83KYq7*XLsiA.null"
         * 
         * When it is interrogated, it will appear twice in the interrogation list as:
         * "VIP_KUf6k4VfAA83KYq7*XLsiA.null = 0"
		 * "VIP_KUf6k4VfAA83KYq7*XLsiA.null = 1"
         * 
         * To determine the state of the radiobutton you would use the form:
         * 
         * pDFFileManager.getPDCheckbox("VIP_KUf6k4VfAA83KYq7*XLsiA.null","0").isChecked()
         * 
         * @param fullyQualifiedName
         * @return - PDCheckbox or null if not found
         */
        public PDCheckbox getPDCheckbox(String fullyQualifiedName, String onValue)
        {
        	PDCheckbox checkbox = null;
            for(int i = 0; i < pdFieldList.size();i++)
            {
                PDField field = pdFieldList.get(i);
            	if(field instanceof PDCheckbox)
            	{
	                try
	                {	                    
	                    if(field.getFullyQualifiedName().equalsIgnoreCase(fullyQualifiedName) && ((PDCheckbox)field).getOnValue().equalsIgnoreCase(onValue))
	                    {
	                    	checkbox = (PDCheckbox)field;
	                        break;
	                    }
	                }
	                catch(IOException e)
	                {
	                    e.printStackTrace();
	                }
            	}
            }
            return checkbox;
        }

V/R,
Mark Strein

TRAC-FLVN
Wargaming and Simulations Directorate
Analytic Tools Division - Paving Crew
Keeper of the Codes
913-684-9309



-----Original Message-----
From: Wojack, Robert (USTP) [mailto:Robert.Wojack@usdoj.gov] 
Sent: Wednesday, March 23, 2016 10:52 AM
To: users@pdfbox.apache.org
Subject: [Non-DoD Source] How to bind distinct OnValues for checkbox group?

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:     Robert.Wojack@usdoj.gov<ma...@usdoj.gov>
Onsite Phone Number:    TBD
Cell#:                              (301)910-9975


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org