pdfacrofields

Problem implementing PDF radio button fields


I'm currently in the process of implementing support for AcroForm for HexaPDF. Check boxes are already working fine but radio buttons give me a headache.

I created a simple PDF with two radio buttons. As far as I can tell the resulting PDF contains the needed objects and is structured according to the the PDF 1.7 specification. However, at least in Adobe Reader and Evince clicking on the radio buttons does nothing.

From the PDF:

Comparing the provided file to PDF files created with other tools didn't lead me to any change I could make to the radio buttons so that they work correctly.

I would appreciate any pointers as to what I'm doing wrong - thanks!


Solution

  • Turns out the field flags /Ff were wrongly set due to the age old "off by one" indexing error. The PDF specification uses 1-based indices in the bit descriptions, Ruby uses 0-based indices when accessing individual bits of an integer.

    Therefore the "radio" bit was not set and thus the buttons couldn't work because they weren't radio buttons.

    After changing the indexing the PDF can now be viewed fine in the viewers.