use of com.tom_roush.pdfbox.pdmodel.fdf.FDFDocument in project PdfBox-Android by TomRoush.
the class PDAcroForm method exportFDF.
/**
* This will export all FDF form data.
*
* @return An FDF document used to export the document.
* @throws IOException If there is an error when exporting the document.
*/
public FDFDocument exportFDF() throws IOException {
FDFDocument fdf = new FDFDocument();
FDFCatalog catalog = fdf.getCatalog();
FDFDictionary fdfDict = new FDFDictionary();
catalog.setFDF(fdfDict);
List<FDFField> fdfFields = new ArrayList<FDFField>();
List<PDField> fields = getFields();
for (PDField field : fields) {
fdfFields.add(field.exportFDF());
}
fdfDict.setID(document.getDocument().getDocumentID());
if (!fdfFields.isEmpty()) {
fdfDict.setFields(fdfFields);
}
return fdf;
}
use of com.tom_roush.pdfbox.pdmodel.fdf.FDFDocument 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