pdfbox-users mailing list archives

Hi,
I'm using 2.0.0-RC3 and trying to add a push button to submit the form to a
web app.
Following the samples, I wrote the following code.
I can add boder and backgorund color to the Text Field. But the Push Button
is still invisible. I can click on it but I can't see it.
What is wrong?
// Add a new AcroForm and add that to the document
PDAcroForm acroForm = new PDAcroForm(doc);
doc.getDocumentCatalog().setAcroForm(acroForm);
// Add and set the resources and default appearance at the form
level
acroForm.setDefaultResources(resources);
String defaultAppearanceString = "/Helv 0 Tf 0 g";
acroForm.setDefaultAppearance(defaultAppearanceString);
// Add a form field to the form.
PDTextField textBox = new PDTextField(acroForm);
textBox.setPartialName("SampleField");
// Acrobat sets the font size to 12 as default
// This is done by setting the font size to '12' on the
// field level.
defaultAppearanceString = "/Helv 12 Tf 0 g";
textBox.setDefaultAppearance(defaultAppearanceString);
// add the field to the acroform
acroForm.getFields().add(textBox);
// Specify the annotation associated with the field
PDAnnotationWidget widget = textBox.getWidgets().get(0);
PDRectangle rect = new PDRectangle(50, 750, 100, 20);
widget.setRectangle(rect);
PDAppearanceCharacteristicsDictionary fieldAppearance = new
PDAppearanceCharacteristicsDictionary(new COSDictionary());
PDColor blue = new PDColor(new float[] { 0, 0, 1 },
PDDeviceRGB.INSTANCE);
fieldAppearance.setBorderColour(blue);
widget.setAppearanceCharacteristics(fieldAppearance);
// Add the annotation to the page
page.getAnnotations().add(widget);
// set the field value
textBox.setValue("Sample field");
// Add a form field to the form.
PDPushButton pb = new PDPushButton(acroForm);
pb.setPartialName("push");
// add the field to the acroform
acroForm.getFields().add(pb);
// Specify the annotation associated with the field
widget = pb.getWidgets().get(0);
rect = new PDRectangle(250, 730, 100, 20);
widget.setRectangle(rect);
fieldAppearance = new PDAppearanceCharacteristicsDictionary(new
COSDictionary());
blue = new PDColor(new float[] { 0, 0, 1 }, PDDeviceRGB.INSTANCE);
fieldAppearance.setBorderColour(blue);
fieldAppearance.setBackground(blue);
fieldAppearance.setNormalCaption("teste");
widget.setAppearanceCharacteristics(fieldAppearance);
// Add the annotation to the page
page.getAnnotations().add(widget);
contents.close();
doc.save(filename);
Clóvis