Search in sources :

Example 11 with PDAcroForm

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;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDAcroForm(com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm)

Example 12 with PDAcroForm

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");
}
Also used : PDAcroForm(com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm)

Example 13 with PDAcroForm

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

Example 14 with PDAcroForm

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();
}
Also used : FDFField(com.tom_roush.pdfbox.pdmodel.fdf.FDFField) FDFDocument(com.tom_roush.pdfbox.pdmodel.fdf.FDFDocument) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PDAcroForm(com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

PDAcroForm (com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm)14 PDField (com.tom_roush.pdfbox.pdmodel.interactive.form.PDField)8 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)6 PDSignatureField (com.tom_roush.pdfbox.pdmodel.interactive.form.PDSignatureField)4 File (java.io.File)4 Test (org.junit.Test)4 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)2 PDDocumentCatalog (com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)2 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)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 PDTextField (com.tom_roush.pdfbox.pdmodel.interactive.form.PDTextField)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)1 COSArray (com.tom_roush.pdfbox.cos.COSArray)1 COSDocument (com.tom_roush.pdfbox.cos.COSDocument)1 COSName (com.tom_roush.pdfbox.cos.COSName)1