Forms width/height not working for RadioButtonField

Hi there,

I am not sure whether I am using this correctly, but when i iterate over the
document.getForm().iterator()

if I get widgetAnnotation instanceof SignatureField I can read Height, Width, rectangle positions quite fine, but when I get
widgetAnnotation instanceof RadioButtonField all those values are 0.

How can I get the width, height, rectangle of a RadioButtonField? What clue am I missing?

Thanks in advance

To retrieve the width, height, and rectangle of a RadioButtonField, you need to ensure that you are correctly accessing the properties of the field after it has been added to the document. The RadioButtonField itself does not have direct properties for width and height; instead, these values are derived from the Rectangle object that defines the position and size of the radio button options.

When you add options to a RadioButtonField, you specify their positions using Rectangle objects. Each option’s rectangle defines its dimensions. Here’s a brief example of how to add a RadioButtonField and access its options:

// Instantiate a Document object
Document pdfDocument = new Document();
// Add a page to the PDF document
pdfDocument.getPages().add();
// Instantiate a RadioButtonField object
RadioButtonField radio = new RadioButtonField(pdfDocument.getPages().get_Item(1));

// Add radio button options with specified rectangles
radio.addOption("Option1", new Rectangle(20, 720, 40, 740)); // Rectangle(x1, y1, x2, y2)
radio.addOption("Option2", new Rectangle(120, 720, 140, 740));

// Add the radio button to the form
pdfDocument.getForm().add(radio);
// Save the PDF document
pdfDocument.save("RadioButtonSample.pdf");

// Accessing the rectangle of the first option
Rectangle optionRectangle = radio.getOptions().get_Item(0).getRectangle();
double width = optionRectangle.getWidth();
double height = optionRectangle.getHeight();

In this example, after adding the options to the RadioButtonField, you can access the rectangle of each option to get its width and height. Make sure to check the rectangle of the specific option you are interested in, as each option can have different dimensions.

If you are still encountering issues with the values being zero, ensure that the RadioButtonField has been properly initialized and that options have been added with valid rectangle dimensions.

No candidates found for method call radio. getOptions().get_Item(0).getRectangle().

Tested Version is 24.7.

Is it correct that the width and height of the Option is just the size of the radiobutton and not the adjacent text?

@Grendel

We need to investigate this scenario in details further. If possible, could you please share a sample PDF for our reference so that we can log an investigation ticket and share the ID with you.

Hello there,

sure, please find attached a pdf I used to experiment with to retrieve the values.
radiobutton.pdf (175.8 KB)

@Grendel

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-44261

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.