pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wojack, Robert (USTP)" <Robert.Woj...@usdoj.gov>
Subject RE: UPDATE! -- How to bind distinct OnValues for checkbox group?
Date Mon, 28 Mar 2016 20:58:12 GMT
Hi Maruan,

I made this minor change to retrieve the NormalAppearance, and it worked. Thanks for basically
providing the solution.



		PDRadioCollection radioCollection = (PDRadioCollection) field;

		PDCheckbox onCheckbox = (PDCheckbox) radioCollection.getKids().get(1);
		PDAppearanceDictionary apDictionary = onCheckbox.getWidget().getAppearance();
		
		// get the fields normal appearances i.e. the options to be selected
		Map<String,PDAppearanceStream> normalAppearances = apDictionary.getNormalAppearance();


-----Original Message-----
From: Wojack, Robert (USTP) [mailto:Robert.Wojack@usdoj.gov] 
Sent: Monday, March 28, 2016 4:51 PM
To: users@pdfbox.apache.org
Subject: RE: How to bind distinct OnValues for checkbox group?

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) <Robert.Wojack@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) <Robert.Wojack@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) <Robert.Wojack@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<mailto:Robert.Wojack@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


Mime
View raw message