Hi Tilman, Right, I stared at PDFDebugger for a half hour and all I could determine was the square used ZapfDingbats. That was after I spent a half hour searching the API.
My application makes round buttons already. I figure the square buttons have something to do with Appearance Streams. I looked at the SO article, but am not gaining any enlightenment regarding square radio buttons, though that may be my fault. I put a PDFDebugger view at http://aapro.net/temp/squarebuttonPDFDebuggerScreenshot.jpg in case that is helpful. I've looked around a lot more that that view indicates, but maybe someone can suggest where I need to be looking based on that screen shot. Also (I hope it isn't too lengthy), I'll post my radio button code. Maybe someone can remind me what portion of this is likely relevant. I sort of remember looking at the PDFBox source quite a bit back in 2016 for this, but have since forgotten all the details, and wish not to have to go fully down that rabbit hole again. (I don't fit down rabbit holes as well as I did in my younger days.) private static void addRadiobuttonAtRect(PDPage page, PDAcroForm acroForm, String name, Map<String, String> optionMap, PDRectangle rect, GroupInfo groupInfo, String dflt) { PDAnnotationWidget radioButton = new PDAnnotationWidget(); String grp = Utils.unescapeChar(optionMap.get("grp")); System.out.println("grp=" + grp + "; name=" + name + "; num=" + optionMap.get("num")); radioButton.setRectangle(rect); int wd = Utils.getInt(optionMap.get("wd")); if (wd == -1) { System.out.println("Zero or invalid wd of radio button '" + optionMap.get("wd") + "'"); wd = 8; } rect.setUpperRightX(rect.getLowerLeftX() + wd); PDFormFieldAdditionalActions fieldActions = new PDFormFieldAdditionalActions(); PDAnnotationAdditionalActions annotationActions = new PDAnnotationAdditionalActions(); setWidgetActions(optionMap, fieldActions, annotationActions); radioButton.setActions(annotationActions); PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary()); if (Utils.getInt(optionMap.get("brdwt")) != 0) { /* * For borderWeight of zero to work reliably (and not exhibit a thin rule), * it is important not so set any border color. */ fieldAppearance.setBorderColour(Utils.hexToPDColor(optionMap.get("brdclr"))); } fieldAppearance.setBackground(Utils.hexToPDColor(optionMap.get("bclr"))); radioButton.setAppearanceCharacteristics(fieldAppearance); radioButton.setAnnotationFlags(4); radioButton.setPage(page); PDRadioButton radioGroupWidget = (PDRadioButton) groupInfo.getGroupButton(); radioButton.setParent(radioGroupWidget); COSDictionary apNDict = new COSDictionary(); COSStream offNStream = new COSStream(); offNStream.setItem(COSName.BBOX, rect); offNStream.setItem(COSName.FORMTYPE, COSInteger.ONE); offNStream.setItem(COSName.TYPE, COSName.XOBJECT); offNStream.setItem(COSName.SUBTYPE, COSName.FORM); apNDict.setItem(COSName.Off, offNStream); COSStream onNStream = new COSStream(); onNStream.setItem(COSName.BBOX, rect); onNStream.setItem(COSName.FORMTYPE, COSInteger.ONE); onNStream.setItem(COSName.TYPE, COSName.XOBJECT); onNStream.setItem(COSName.SUBTYPE, COSName.FORM); apNDict.setItem(name, onNStream); COSDictionary apDDict = new COSDictionary(); COSStream offDStream = new COSStream(); offDStream.setItem(COSName.BBOX, rect); offDStream.setItem(COSName.FORMTYPE, COSInteger.ONE); offDStream.setItem(COSName.TYPE, COSName.XOBJECT); offDStream.setItem(COSName.SUBTYPE, COSName.FORM); apDDict.setItem(COSName.Off, offDStream); COSStream onDStream = new COSStream(); onDStream.setItem(COSName.BBOX, rect); onDStream.setItem(COSName.FORMTYPE, COSInteger.ONE); onDStream.setItem(COSName.TYPE, COSName.XOBJECT); onDStream.setItem(COSName.SUBTYPE, COSName.FORM); apDDict.setItem(name, onDStream); PDAppearanceDictionary appearance = new PDAppearanceDictionary(); PDAppearanceEntry appearanceNEntry = new PDAppearanceEntry(apNDict); appearance.setNormalAppearance(appearanceNEntry); PDAppearanceEntry appearanceDEntry = new PDAppearanceEntry(apDDict); appearance.setDownAppearance(appearanceDEntry); radioButton.setAppearance(appearance); if ((dflt != null) && dflt.equals("Yes")) { radioButton.setAppearanceState(name); } else { radioButton.setAppearanceState("Off"); } // Add the annotation to the group. groupInfo.addItem(radioButton); try { page.getAnnotations().add(radioButton); } catch (IOException exc) { System.out.println("IOException adding readioButton to page: " + exc.getMessage()); } } Thanks, Gary -----Original Message----- From: Tilman Hausherr <[email protected]> Sent: Tuesday, July 24, 2018 1:43 PM To: [email protected] Subject: Re: How to get square radio button It is tricky... one needs to look with PDFDebugger how Adobe does it and then you copy that. Here's my attempt with round buttons. https://stackoverflow.com/questions/41631119/radiobutton-display-problems-with-pdfbox/41632982 I looked how the square buttons are done... it is similar except that a font is used. Not sure if this is needed or whether it is for text extraction. Tilman Am 24.07.2018 um 15:35 schrieb Gary Grosso: > Users of a fillable form application have come back asking for the ability to > have a square radio button. > > Acrobat gives a dialog, Radio Button Properties, with Options > Button Style, > which can be set to check, circle, cross, diamond, square, or star. > > I have been trying to understand how this is implemented using PDFBox, but > have not had any luck. > > The sample PDF is at http://aapro.net/temp/squarebutton.pdf > > While "How to get square radio button" is what I'm required to know, "How to > have figured that out using PDFBox" would also be of interest and appreciated. > > Thanks, > Gary > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

