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);

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.

Reply via email to