0

Here is my following code :

for (PDField field: listFields) {
                    
                            if (champs instanceof PDRadioButton) {
                                
                                PDRadioButton pdRB = (PDRadioButton) champs;
                                System.out.println(pdRB.getValueAsString());
                            
                            }

I have a pdf with a radio button selection.

O : Group 1 O : Group 2 O : Group 3

I want to get the String value (like Group 1)

But i can only get the int value "1 , 2 or 3" i tried every PDRadioButtion function that return a String and no one give me "Group1, .."

Do you have any solutions ? Does the problem come from the PDF form ? Thanks !

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
Treasm
  • 23
  • 4
  • "Group 1" is an ordinary text. There are ways to connect a text to a button, but obviously your PDF hasn't done that. – Tilman Hausherr Mar 31 '21 at 10:37
  • Okay so when a text will be connected to the button, i'll be able to get the String thanks to a PDRadioButton function ? – Treasm Mar 31 '21 at 11:13
  • Yes, `getValue()` will return the text value if your PDF form is set that way. See the `CreateRadioButtons.java` example in the source code, and the `TestCreateSimpleForms.testRadioButtons()` unit test. – Tilman Hausherr Mar 31 '21 at 11:53
  • the PDF is made with open office, actually getValue() returns me "Group" (i named the group of radiobuttons like that). In the pdf settings, i also put a label "Groupe 1" , "2", "3" for each radio buttons but i didn't really get how i can get these values, i can only get the index value.. – Treasm Mar 31 '21 at 12:10
  • `getValue()`, `getSelectedIndex()` or `getSelectedExportValues()`. Try them. But if you just get 1, 2 and 3, what prevents you from having your own logic that knows what the values mean for this specific PDF? – Tilman Hausherr Mar 31 '21 at 12:15
  • my bad, here is what i get : getPartialName() -> Group / getValue() -> Off / getValueAsString() -> Off / getSelectedIndex() -> -1 / getSelectedExportValues() ->Off / the problem is that on this PDF i'll have like 10 differents groups of radiobuttons so i think that i can work with "1,2,3" values only once – Treasm Mar 31 '21 at 12:23
  • But these are different button objects. You can their name with `getFullyQualifiedName()`. Or you get the field directly with `PDAcroForm.getField(fieldName)`. – Tilman Hausherr Mar 31 '21 at 12:29
  • yeah actually getFullyQualifiedNamed() returns me "Group", well ill give an other exemple because its confusing with "Group" and "Group 1". I have a group a radio button named "Radios" and i have 2 radios : O Label1 O Label2. And for each elements that are radio buttons, i wanna print their label (so Label1, Label2) I don't really understand why do i only get the label of the group of radio buttons (Radios) and not the label of each radio buttons (Label1, Label2) – Treasm Mar 31 '21 at 12:42
  • That's the way it works, the pdradiobutton is an object with widgets and these widgets are the individual buttons. Setting the names properly is your responsibility in OpenOffice, if it is possible at all. If it isn't possible then use a different software to design your form. To understand more, open your PDF file with PDFDebugger and switch to the "Show internal structure" mode. – Tilman Hausherr Mar 31 '21 at 12:48
  • Okay so if is it set properly, getValue() should return me "Label1" and not "Off" ? – Treasm Mar 31 '21 at 12:54
  • Yes if OpenOffice can configure export values. – Tilman Hausherr Mar 31 '21 at 12:55
  • Okay thanks for helping ! – Treasm Mar 31 '21 at 12:57

0 Answers0