pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Grosso <gary.gro...@oberontech.com>
Subject Setting one radio button on by default
Date Mon, 17 Jul 2017 19:59:56 GMT
I know this has been answered before, but when I look at the answers, I have to wonder if there
is now an easier way.

Below is my code which is all I need to display working radio buttons.

What is the minimum I need to do to set one of a group of buttons on by default? I'm hoping
it's easier than all of https://www.mail-archive.com/users@pdfbox.apache.org/msg08490.html
but if that's really all necessary, so be it...

Thanks,
Gary

        private static void addRadiobuttonAtRect(PDPage page, PDAcroForm acroForm, String
name,
                        Map<String, String> optionMap, PDRectangle rect) {
        PDRadioButton radioButton = new PDRadioButton(acroForm);

        String grp = Utils.unescapeChar(optionMap.get("grp"));
        radioButton.setPartialName(grp);

        acroForm.getFields().add(radioButton);

        // Specify the annotation associated with the field and its location.
        PDAnnotationWidget widget = radioButton.getWidgets().get(0);
        widget.setRectangle(rect);
        rect.setLowerLeftX((float) (rect.getLowerLeftX() - 18));
        rect.setUpperRightX((float) (rect.getLowerLeftX() + 10));

        widget.setPage(page);

        PDAppearanceCharacteristicsDictionary fieldAppearance
                = new PDAppearanceCharacteristicsDictionary(new COSDictionary());
                fieldAppearance.setBorderColour(Utils.hexToPDColor(optionMap.get("brdclr")));
                fieldAppearance.setBackground(Utils.hexToPDColor(optionMap.get("bclr")));
        widget.setAppearanceCharacteristics(fieldAppearance);

        // make sure the annotation is visible on screen and paper
        widget.setPrinted(true);

        // Add the annotation to the page
        try {
                        page.getAnnotations().add(widget);
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message