pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilad Denneboom <gilad.denneb...@gmail.com>
Subject Re: checkbox field
Date Wed, 08 Mar 2017 16:41:49 GMT
I'd also recommend setting the NeedsAppearances flag to TRUE.

On Wed, Mar 8, 2017 at 2:57 PM, chitgoks <chitgoks@gmail.com> wrote:

> 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);
>

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