Hi Hendrik,

the form field is created and visible in Adobe Reader if the Highlight Fields 
option is activated. In order to let the field stand out in an unactivated 
state you need to modify the visual representation of the Field.

> Hello,
> 
> we want to create a pdf-document containing form elements like textbox or 
> checkbox. Unfortunately in the pdf-output of our test programm the form 
> elements are not visible. Just a blank page is produced. Can you tell us, 
> what we are missing or doing wrong. We are using pdfbox 1.8.4. Our source 
> code is:
> 
> PDDocument doc = new PDDocument();
> PDPage page = new PDPage();
> doc.addPage(page);
> 
> PDAcroForm acroForm = new PDAcroForm(doc);
> doc.getDocumentCatalog().setAcroForm(acroForm);
> 
> COSDictionary dictionary = new COSDictionary();
> 
> COSArray rect = new COSArray();
> rect.add(new COSFloat(10f)); // lower x boundary
> rect.add(new COSFloat(10f)); // lower y boundary
> rect.add(new COSFloat(200f)); // upper x boundary
> rect.add(new COSFloat(100f)); // upper y boundary
> 
> dictionary.setItem(COSName.RECT, rect);
> dictionary.setItem(COSName.FT, COSName.getPDFName("Tx")); // Field Type Text
> // Type
> dictionary.setItem(COSName.TYPE, COSName.ANNOT);
> dictionary.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget"));
> dictionary.setItem(COSName.T, new COSString("yourFieldName"));
> 
> PDTextbox textBox = new PDTextbox(acroForm, dictionary);
> 

// get the annotation widget for the field
PDAnnotationWidget fieldAnnot = textBox.getWidget();
                
// define a general field appearance. This could be applied to multiple fields 
if needed
// as well multiple different styles could be defined
PDAppearanceCharacteristicsDictionary fieldAppearance = new 
PDAppearanceCharacteristicsDictionary(new COSDictionary());
PDGamma colourBlue = new PDGamma();
colourBlue.setB(1);
fieldAppearance.setBorderColour(colourBlue);

// define a general border style. This could be applied to multiple fields if 
needed
// as well multiple different styles could be defined
PDBorderStyleDictionary fieldBorderStyle = new PDBorderStyleDictionary();
fieldBorderStyle.setStyle(PDBorderStyleDictionary.STYLE_SOLID);
fieldBorderStyle.setWidth(2f);

// set the field appearance for the field’s annotation
fieldAnnot.setAppearanceCharacteristics(fieldAppearance);
// set the border appearance for the field’s annotation
fieldAnnot.setBorderStyle(fieldBorderStyle);



> acroForm.getFields().add(textBox);
> page.getAnnotations().add(textBox.getWidget());
> 
> doc.save("c:/temp/checkbox.pdf");
> doc.close();
> 
> 
> Your help would be much appreciated,
> 
> Hendrik Warneke
> 
> Kassenärztliche Vereinigung Niedersachsen  |  Körperschaft des öffentlichen 
> Rechts  |  Berliner Allee 22  |  30175 Hannover
> Vorstand: Mark Barjenbruch (Vorsitzender), Dr. Jörg Berling  |  
> Vertreterversammlung: Dr. Christoph Titz (Vorsitzender)
> 
> P Bitte denken Sie an die Umwelt, bevor Sie diese E-Mail ausdrucken.

BR
Maruan

Reply via email to