use of com.tom_roush.pdfbox.pdmodel.interactive.form.PDTextField in project PdfBox-Android by TomRoush.
the class MainActivity method fillForm.
/**
* Fills in a PDF form and saves the result
*/
public void fillForm(View v) {
try {
// Load the document and get the AcroForm
PDDocument document = PDDocument.load(assetManager.open("FormTest.pdf"));
PDDocumentCatalog docCatalog = document.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
// Fill the text field
PDTextField field = (PDTextField) acroForm.getField("TextField");
field.setValue("Filled Text Field");
// Optional: don't allow this field to be edited
field.setReadOnly(true);
PDField checkbox = acroForm.getField("Checkbox");
((PDCheckBox) checkbox).check();
PDField radio = acroForm.getField("Radio");
((PDRadioButton) radio).setValue("Second");
PDField listbox = acroForm.getField("ListBox");
List<Integer> listValues = new ArrayList<>();
listValues.add(1);
listValues.add(2);
((PDListBox) listbox).setSelectedOptionsIndex(listValues);
PDField dropdown = acroForm.getField("Dropdown");
((PDComboBox) dropdown).setValue("Hello");
String path = root.getAbsolutePath() + "/FilledForm.pdf";
tv.setText("Saved filled form to " + path);
document.save(path);
document.close();
} catch (IOException e) {
Log.e("PdfBox-Android-Sample", "Exception thrown while filling form fields", e);
}
}
use of com.tom_roush.pdfbox.pdmodel.interactive.form.PDTextField in project PdfBox-Android by TomRoush.
the class PDAnnotationTest method createWidgetAnnotationFromField.
@Test
public void createWidgetAnnotationFromField() {
PDDocument document = new PDDocument();
PDAcroForm acroForm = new PDAcroForm(document);
PDTextField textField = new PDTextField(acroForm);
PDAnnotation annotation = textField.getWidgets().get(0);
assertEquals(COSName.ANNOT, annotation.getCOSObject().getItem(COSName.TYPE));
assertEquals(PDAnnotationWidget.SUB_TYPE, annotation.getCOSObject().getNameAsString(COSName.SUBTYPE));
}
Aggregations