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:34:33 GMT
this is weird. the checkbox showed when i called
this acroForm.setNeedAppearances(true);

it would be nice to include a checkbox group and radio button group example
code in the repository.

im currently working on those. so i made the checkbox appear, now ill try
to make radio button group work

will update on what i can come up as well


Website/Java Games: http://www.chitgoks.com
My Blogs:
http://tech.chitgoks.com
http://wuhtevah.chitgoks.com
http://disneyusa.blogspot.com

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

> Hi,
> > Am 08.03.2017 um 15:10 schrieb chitgoks <chitgoks@gmail.com>:
> >
> > hi maruan
> >
> > there is a PDAppearanceCharacteristicsDictionary at the bottom of the
> code
> > before the widget is added to the annotations list
>
> PDAppearanceCharacteristicsDictionary only defines settings for the
> creation of the appearance stream but doesn't create it. What you need is
> the content of the appearance stream.
>
> Unfortunately I'm in the middle of a project so can't help much further at
> the moment.
>
> What you could do if the form is opened in Adobe Acrobat or Reader is to
> set the NeedAppearances flag for the AcroForm. This will trigger Adobe
> Reader/Acrobat to build the appearance once the form is opened. This shall
> only be treated as a workaround as this will not work in most other readers
> or when rendering the form throufgh PDFBox or others.
>
> I'll try to get something prepared tomorrow morning for you if you havn't
> found a solution by then.
>
> BR
> Maruan
>
> >
> > 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
> >>
> >>
>
>
> ---------------------------------------------------------------------
> 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