Hi Tilman,
I'm using PDFBox version 2.0.17.  Here is my code:

 public void fillForm(Map<String, String> formMap)
{

File file = new File(myFile);

try (PDDocument doc = PDDocument.load(file)) {

PDDocumentCatalog docCatalog = doc.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();

if (acroForm != null) {

for (Map.Entry<String, String> entry : formMap.entrySet()) {
String key = entry.getKey();
PDField field = acroForm.getField(key);

if (field instanceof PDVariableText) {

if (field instanceof PDTextField) {
PDTextField textField = PDTextField.class.cast(field);
textField.setValue(formMap.get(key));

} else if (field instanceof PDChoice) {
PDChoice choice = PDChoice.class.cast(field);
choice.setValue(formMap.get(key));

}
} else if (field instanceof PDCheckBox) {
PDCheckBox checkBox = PDCheckBox.class.cast(field);
boolean value = Boolean.valueOf(formMap.get(key));
if (value) {
checkBox.check();
} else {
checkBox.unCheck();
}

} else if (field instanceof PDRadioButton) {
PDRadioButton radioButton = PDRadioButton.class.cast(field);
radioButton.setValue(formMap.get(key));

}
}

File outputFile = new File("test.pdf");
doc.save(outputFile);
}
} catch (IOException e) {
throw new AssistBusinessException(e);
}
}

}

On Tue, Dec 24, 2019 at 10:43 AM Tilman Hausherr <thaush...@t-online.de>
wrote:

> Am 23.12.2019 um 22:09 schrieb Robert Pepersack:
> > 2. Run my Java program that loads the .pdf file, populates its form
> > fields, and saves it to a new file on my local disk.
>
> What code did you use to populate the date field, and what PDFBox
> version did you use (the current version is 2.0.18)? I'm asking because
> the date field does not have an appearance stream.
>
> Tilman
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
> For additional commands, e-mail: users-h...@pdfbox.apache.org
>
>

Reply via email to