Search in sources :

Example 6 with FDFField

use of com.tom_roush.pdfbox.pdmodel.fdf.FDFField 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

FDFField (com.tom_roush.pdfbox.pdmodel.fdf.FDFField)6 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)2 FDFDocument (com.tom_roush.pdfbox.pdmodel.fdf.FDFDocument)2 ArrayList (java.util.ArrayList)2 COSObjectable (com.tom_roush.pdfbox.pdmodel.common.COSObjectable)1 FDFCatalog (com.tom_roush.pdfbox.pdmodel.fdf.FDFCatalog)1 FDFDictionary (com.tom_roush.pdfbox.pdmodel.fdf.FDFDictionary)1 PDAcroForm (com.tom_roush.pdfbox.pdmodel.interactive.form.PDAcroForm)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1