hi tilman. i need help on checkbox creation. im creating a group of
checkbox but the thing is, it does not show in pdf. i tried sample code i
found even in stackoverflow but they do not get shown in pdf when viewed.
even if i add 1 checkbox nothing gets shown.
here is my code. please advise thank you
--------------------------------------------------------------------------------------------------------
f (pdfDocument.getDocumentCatalog().getAcroForm() == null) {
pdfDocument.getDocumentCatalog().setAcroForm(new
PDAcroForm(pdfDocument));
}
PDAcroForm cbAcroForm = pdfDocument.getDocumentCatalog().getAcroForm();
PDCheckBox checkBox = new PDCheckBox(cbAcroForm);
checkBox.setPartialName("cb");
checkBox.setMappingName(checkBox.getPartialName());
checkBox.getCOSObject().setString(COSName.DA, "/Helv 0 Tf 0 g");
// Replace yes value with checkbox value.
COSBase yes = checkBox.getCOSObject().getDictionaryObject(COSName.YES);
checkBox.getCOSObject().setItem("value here", yes);
checkBox.getCOSObject().removeItem(COSName.YES);
cbAcroForm.getFields().add(checkBox);
PDAnnotationWidget cbWidget = new PDAnnotationWidget();
cbWidget.setRectangle(location);
cbWidget.setPage(pdPage);
cbWidget.setModifiedDate(DateTool.convertDateToCalendar(annotation.getDateModified()));
cbWidget.getCOSObject().setString(COSName.NM,
annotation.getComments().get(0).getUsername());
cbWidget.setPrinted(true);
PDAppearanceCharacteristicsDictionary cbAppearance = new
PDAppearanceCharacteristicsDictionary(new COSDictionary());
cbAppearance.setBackground(Util.hex2PDColor("#000000"));
cbAppearance.setBorderColour(Util.hex2PDColor("#ffffff"));
cbWidget.setAppearanceCharacteristics(cbAppearance);
pdPage.getAnnotations().add(cbWidget);