pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: checkbox field
Date Wed, 08 Mar 2017 14:06:33 GMT
scanning quickly through your code it looks fine. But what is missing - and that's the reason
that you don't see anything - is the appearance stream for the checkbox. The best thing is
to look at a sample PDF and replicate the appearance stream for that.

BR
Maruan

> Am 08.03.2017 um 14:57 schrieb chitgoks <chitgoks@gmail.com>:
> 
> 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);


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message