use of com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm in project PdfBox-Android by TomRoush.
the class PDDocumentCatalog method getAcroForm.
/**
* Get the documents AcroForm. This will return null if no AcroForm is part of the document.
*
* @return The document's AcroForm.
*/
public PDAcroForm getAcroForm() {
if (cachedAcroForm == null) {
COSDictionary dict = (COSDictionary) root.getDictionaryObject(COSName.ACRO_FORM);
cachedAcroForm = dict == null ? null : new PDAcroForm(document, dict);
}
return cachedAcroForm;
}
use of com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm in project PdfBox-Android by TomRoush.
the class PDVisibleSigBuilder method createAcroForm.
@Override
public void createAcroForm(PDDocument template) {
PDAcroForm theAcroForm = new PDAcroForm(template);
template.getDocumentCatalog().setAcroForm(theAcroForm);
pdfStructure.setAcroForm(theAcroForm);
Log.i("PdfBox-Android", "AcroForm has been created");
}
use of com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm in project PdfBox-Android by TomRoush.
the class MergeAcroFormsTest method testJoinFieldsMerge_TextFieldsOnly_SameMerged.
/*
* Test Join Field Merge for text fields only and same source documents
*/
@Test
public void testJoinFieldsMerge_TextFieldsOnly_SameMerged() throws IOException {
PDFMergerUtility merger = new PDFMergerUtility();
File toBeMerged = new File(IN_DIR, "AcroFormForMerge-TextFieldsOnly.pdf");
File pdfOutput = new File(OUT_DIR, "PDFBoxJoinFieldsMerge-TextFieldsOnly-SameMerged.pdf");
merger.setDestinationFileName(pdfOutput.getAbsolutePath());
merger.addSource(toBeMerged);
merger.addSource(toBeMerged);
merger.setAcroFormMergeMode(AcroFormMergeMode.JOIN_FORM_FIELDS_MODE);
merger.mergeDocuments(null);
PDDocument compliantDocument = null;
PDDocument toBeCompared = null;
try {
compliantDocument = PDDocument.load(new File(IN_DIR, "AcrobatMerge-TextFieldsOnly-SameMerged.pdf"));
toBeCompared = PDDocument.load(new File(OUT_DIR, "PDFBoxJoinFieldsMerge-TextFieldsOnly-SameMerged.pdf"));
PDAcroForm compliantAcroForm = compliantDocument.getDocumentCatalog().getAcroForm();
PDAcroForm toBeComparedAcroForm = toBeCompared.getDocumentCatalog().getAcroForm();
assertEquals("There shall be the same number of root fields", compliantAcroForm.getFields().size(), toBeComparedAcroForm.getFields().size());
for (PDField compliantField : compliantAcroForm.getFieldTree()) {
assertNotNull("There shall be a field with the same FQN", toBeComparedAcroForm.getField(compliantField.getFullyQualifiedName()));
PDField toBeComparedField = toBeComparedAcroForm.getField(compliantField.getFullyQualifiedName());
compareFieldProperties(compliantField, toBeComparedField);
}
for (PDField toBeComparedField : toBeComparedAcroForm.getFieldTree()) {
assertNotNull("There shall be a field with the same FQN", compliantAcroForm.getField(toBeComparedField.getFullyQualifiedName()));
PDField compliantField = compliantAcroForm.getField(toBeComparedField.getFullyQualifiedName());
compareFieldProperties(toBeComparedField, compliantField);
}
} finally {
IOUtils.closeQuietly(compliantDocument);
IOUtils.closeQuietly(toBeCompared);
}
}
use of com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm in project PdfBox-Android by TomRoush.
the class TestFDF method checkFields.
private void checkFields(String name) throws IOException, URISyntaxException {
FDFDocument fdf = FDFDocument.load(new File(TestFDF.class.getResource(name).toURI()));
fdf.saveXFDF(new PrintWriter(new ByteArrayOutputStream()));
List<FDFField> fields = fdf.getCatalog().getFDF().getFields();
assertEquals(2, fields.size());
assertEquals("Field1", fields.get(0).getPartialFieldName());
assertEquals("Field2", fields.get(1).getPartialFieldName());
assertEquals("Test1", fields.get(0).getValue());
assertEquals("Test2", fields.get(1).getValue());
PDDocument pdf = PDDocument.load(new File(TestFDF.class.getResource("/pdfbox/com/tom_roush/pdfbox/pdfparser/SimpleForm2Fields.pdf").toURI()));
PDAcroForm acroForm = pdf.getDocumentCatalog().getAcroForm();
acroForm.importFDF(fdf);
assertEquals("Test1", acroForm.getField("Field1").getValueAsString());
assertEquals("Test2", acroForm.getField("Field2").getValueAsString());
pdf.close();
fdf.close();
}
Aggregations