Search in sources :

Example 6 with COSArrayList

use of org.apache.pdfbox.pdmodel.common.COSArrayList in project pdfbox by apache.

the class PDAcroForm method getFields.

/**
 * This will return all of the documents root fields.
 *
 * A field might have children that are fields (non-terminal field) or does not
 * have children which are fields (terminal fields).
 *
 * The fields within an AcroForm are organized in a tree structure. The documents root fields
 * might either be terminal fields, non-terminal fields or a mixture of both. Non-terminal fields
 * mark branches which contents can be retrieved using {@link PDNonTerminalField#getChildren()}.
 *
 * @return A list of the documents root fields, never null. If there are no fields then this
 * method returns an empty list.
 */
public List<PDField> getFields() {
    COSArray cosFields = (COSArray) dictionary.getDictionaryObject(COSName.FIELDS);
    if (cosFields == null) {
        return Collections.emptyList();
    }
    List<PDField> pdFields = new ArrayList<>();
    for (int i = 0; i < cosFields.size(); i++) {
        COSDictionary element = (COSDictionary) cosFields.getObject(i);
        if (element != null) {
            PDField field = PDField.fromDictionary(this, element, null);
            if (field != null) {
                pdFields.add(field);
            }
        }
    }
    return new COSArrayList<>(pdFields, cosFields);
}
Also used : COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) COSArray(org.apache.pdfbox.cos.COSArray) COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList)

Example 7 with COSArrayList

use of org.apache.pdfbox.pdmodel.common.COSArrayList in project pdfbox by apache.

the class PDSeedValue method getLegalAttestation.

/**
 * (Optional, PDF 1.6) An array of text strings that specifying possible legal
 * attestations.
 *
 * @return the reasons that should be used by the signature handler
 */
public List<String> getLegalAttestation() {
    List<String> retval = null;
    COSArray fields = (COSArray) dictionary.getDictionaryObject(COSName.LEGAL_ATTESTATION);
    if (fields != null) {
        List<String> actuals = new ArrayList<>();
        for (int i = 0; i < fields.size(); i++) {
            String element = fields.getString(i);
            if (element != null) {
                actuals.add(element);
            }
        }
        retval = new COSArrayList<>(actuals, fields);
    }
    return retval;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList)

Example 8 with COSArrayList

use of org.apache.pdfbox.pdmodel.common.COSArrayList in project pdfbox by apache.

the class PDSeedValue method getSubFilter.

/**
 * If <b>SubFilter</b> is not null and the {@link #isSubFilterRequired()} indicates this
 * entry is a required constraint, then the first matching encodings shall be used when
 * signing; otherwise, signing shall not take place. If {@link #isSubFilterRequired()}
 * indicates that this is an optional constraint, then the first matching encoding shall
 * be used if it is available. If it is not available, a different encoding may be used
 * instead.
 *
 * @return the subfilter that shall be used by the signature handler
 */
public List<String> getSubFilter() {
    List<String> retval = null;
    COSArray fields = (COSArray) dictionary.getDictionaryObject(COSName.SUB_FILTER);
    if (fields != null) {
        List<String> actuals = new ArrayList<>();
        for (int i = 0; i < fields.size(); i++) {
            String element = fields.getName(i);
            if (element != null) {
                actuals.add(element);
            }
        }
        retval = new COSArrayList<>(actuals, fields);
    }
    return retval;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList)

Example 9 with COSArrayList

use of org.apache.pdfbox.pdmodel.common.COSArrayList in project pdfbox by apache.

the class PDNonTerminalField method getChildren.

/**
 * Returns this field's children. These may be either terminal or non-terminal fields.
 *
 * @return the list of child fields. Be aware that this list is <i>not</i> backed by the
 * children of the field, so adding or deleting has no effect on the PDF document until you call
 * {@link #setChildren(java.util.List) setChildren()} with the modified list.
 */
public List<PDField> getChildren() {
    // TODO: why not return a COSArrayList like in PDPage.getAnnotations() ?
    List<PDField> children = new ArrayList<>();
    COSArray kids = (COSArray) getCOSObject().getDictionaryObject(COSName.KIDS);
    for (int i = 0; i < kids.size(); i++) {
        COSBase kid = kids.getObject(i);
        if (kid instanceof COSDictionary) {
            if (kid.getCOSObject() == this.getCOSObject()) {
                LOG.warn("Child field is same object as parent");
                continue;
            }
            PDField field = PDField.fromDictionary(getAcroForm(), (COSDictionary) kid, this);
            if (field != null) {
                children.add(field);
            }
        }
    }
    return children;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList) COSBase(org.apache.pdfbox.cos.COSBase)

Example 10 with COSArrayList

use of org.apache.pdfbox.pdmodel.common.COSArrayList in project pdfbox by apache.

the class FDFDictionary method getEmbeddedFDFs.

/**
 * This will get the list of embedded FDF entries, or null if the entry is null. This will return a list of
 * PDFileSpecification objects.
 *
 * @return A list of embedded FDF files.
 *
 * @throws IOException If there is an error creating the file spec.
 */
public List<PDFileSpecification> getEmbeddedFDFs() throws IOException {
    List<PDFileSpecification> retval = null;
    COSArray embeddedArray = (COSArray) fdf.getDictionaryObject(COSName.EMBEDDED_FDFS);
    if (embeddedArray != null) {
        List<PDFileSpecification> embedded = new ArrayList<>();
        for (int i = 0; i < embeddedArray.size(); i++) {
            embedded.add(PDFileSpecification.createFS(embeddedArray.get(i)));
        }
        retval = new COSArrayList<>(embedded, embeddedArray);
    }
    return retval;
}
Also used : PDFileSpecification(org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification) COSArray(org.apache.pdfbox.cos.COSArray) COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList)

Aggregations

COSArray (org.apache.pdfbox.cos.COSArray)19 COSArrayList (org.apache.pdfbox.pdmodel.common.COSArrayList)19 ArrayList (java.util.ArrayList)18 COSDictionary (org.apache.pdfbox.cos.COSDictionary)11 COSBase (org.apache.pdfbox.cos.COSBase)5 PDAnnotation (org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation)2 Point (java.awt.Point)1 List (java.util.List)1 COSDocument (org.apache.pdfbox.cos.COSDocument)1 COSString (org.apache.pdfbox.cos.COSString)1 PDFileSpecification (org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification)1 PDAnnotationWidget (org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget)1 PDAcroForm (org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm)1 PDField (org.apache.pdfbox.pdmodel.interactive.form.PDField)1 PDSignatureField (org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField)1 PDThread (org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDThread)1 PDThreadBead (org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead)1