Search in sources :

Example 1 with FDFField

use of com.tom_roush.pdfbox.pdmodel.fdf.FDFField 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;
}
Also used : ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) FDFField(com.tom_roush.pdfbox.pdmodel.fdf.FDFField) FDFDocument(com.tom_roush.pdfbox.pdmodel.fdf.FDFDocument) FDFCatalog(com.tom_roush.pdfbox.pdmodel.fdf.FDFCatalog) FDFDictionary(com.tom_roush.pdfbox.pdmodel.fdf.FDFDictionary)

Example 2 with FDFField

use of com.tom_roush.pdfbox.pdmodel.fdf.FDFField in project PdfBox-Android by TomRoush.

the class PDNonTerminalField method exportFDF.

@Override
FDFField exportFDF() throws IOException {
    FDFField fdfField = new FDFField();
    fdfField.setPartialFieldName(getPartialName());
    fdfField.setValue(getValue());
    List<PDField> children = getChildren();
    List<FDFField> fdfChildren = new ArrayList<FDFField>();
    for (PDField child : children) {
        fdfChildren.add(child.exportFDF());
    }
    fdfField.setKids(fdfChildren);
    return fdfField;
}
Also used : ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) FDFField(com.tom_roush.pdfbox.pdmodel.fdf.FDFField)

Example 3 with FDFField

use of com.tom_roush.pdfbox.pdmodel.fdf.FDFField in project PdfBox-Android by TomRoush.

the class PDAcroForm method importFDF.

/**
 * This method will import an entire FDF document into the PDF document
 * that this acroform is part of.
 *
 * @param fdf The FDF document to import.
 *
 * @throws IOException If there is an error doing the import.
 */
public void importFDF(FDFDocument fdf) throws IOException {
    List<FDFField> fields = fdf.getCatalog().getFDF().getFields();
    if (fields != null) {
        for (FDFField field : fields) {
            FDFField fdfField = field;
            PDField docField = getField(fdfField.getPartialFieldName());
            if (docField != null) {
                docField.importFDF(fdfField);
            }
        }
    }
}
Also used : FDFField(com.tom_roush.pdfbox.pdmodel.fdf.FDFField)

Example 4 with FDFField

use of com.tom_roush.pdfbox.pdmodel.fdf.FDFField in project PdfBox-Android by TomRoush.

the class PDTerminalField method exportFDF.

@Override
FDFField exportFDF() throws IOException {
    FDFField fdfField = new FDFField();
    fdfField.setPartialFieldName(getPartialName());
    fdfField.setValue(getCOSObject().getDictionaryObject(COSName.V));
    return fdfField;
}
Also used : FDFField(com.tom_roush.pdfbox.pdmodel.fdf.FDFField)

Example 5 with FDFField

use of com.tom_roush.pdfbox.pdmodel.fdf.FDFField in project PdfBox-Android by TomRoush.

the class PDNonTerminalField method importFDF.

@Override
void importFDF(FDFField fdfField) throws IOException {
    super.importFDF(fdfField);
    List<FDFField> fdfKids = fdfField.getKids();
    List<PDField> children = getChildren();
    for (int i = 0; fdfKids != null && i < fdfKids.size(); i++) {
        for (COSObjectable pdKid : children) {
            if (pdKid instanceof PDField) {
                PDField pdChild = (PDField) pdKid;
                FDFField fdfChild = fdfKids.get(i);
                String fdfName = fdfChild.getPartialFieldName();
                if (fdfName != null && fdfName.equals(pdChild.getPartialName())) {
                    pdChild.importFDF(fdfChild);
                }
            }
        }
    }
}
Also used : COSObjectable(com.tom_roush.pdfbox.pdmodel.common.COSObjectable) FDFField(com.tom_roush.pdfbox.pdmodel.fdf.FDFField)

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