pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chitgoks <chitg...@gmail.com>
Subject Re: checkbox field
Date Wed, 08 Mar 2017 14:10:49 GMT
hi maruan

there is a PDAppearanceCharacteristicsDictionary at the bottom of the code
before the widget is added to the annotations list

i actually tested code posted in forums that said they worked but nothing
gets shown. im using 2.0.4

thanks

On Wed, Mar 8, 2017 at 10:06 PM, Maruan Sahyoun <sahyoun@fileaffairs.de>
wrote:

> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message