Search in sources :

Example 11 with PDField

use of com.tom_roush.pdfbox.pdmodel.interactive.form.PDField 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);
    }
}
Also used : PDField(com.tom_roush.pdfbox.pdmodel.interactive.form.PDField) PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) PDAcroForm(com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm) File(java.io.File) Test(org.junit.Test)

Aggregations

PDField (com.tom_roush.pdfbox.pdmodel.interactive.form.PDField)11 PDAcroForm (com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm)8 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)4 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)4 COSArray (com.tom_roush.pdfbox.cos.COSArray)3 PDSignatureField (com.tom_roush.pdfbox.pdmodel.interactive.form.PDSignatureField)3 File (java.io.File)3 Test (org.junit.Test)3 COSBase (com.tom_roush.pdfbox.cos.COSBase)2 PDDocumentCatalog (com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)2 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)2 PDAnnotation (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotation)2 PDAnnotationWidget (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget)2 ArrayList (java.util.ArrayList)2 COSDocument (com.tom_roush.pdfbox.cos.COSDocument)1 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)1 COSObjectable (com.tom_roush.pdfbox.pdmodel.common.COSObjectable)1 PDNumberTreeNode (com.tom_roush.pdfbox.pdmodel.common.PDNumberTreeNode)1 PDCheckBox (com.tom_roush.pdfbox.pdmodel.interactive.form.PDCheckBox)1 PDComboBox (com.tom_roush.pdfbox.pdmodel.interactive.form.PDComboBox)1