Search in sources :

Example 16 with COSArrayList

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

the class PDPage method getAnnotations.

/**
 * This will return a list of the annotations for this page.
 *
 * @param annotationFilter the annotation filter provided allowing to filter out specific annotations
 * @return List of the PDAnnotation objects, never null. The returned list is backed by the
 * annotations COSArray, so any adding or deleting in this list will change the document too.
 *
 * @throws IOException If there is an error while creating the annotation list.
 */
public List<PDAnnotation> getAnnotations(AnnotationFilter annotationFilter) throws IOException {
    COSBase base = page.getDictionaryObject(COSName.ANNOTS);
    if (base instanceof COSArray) {
        COSArray annots = (COSArray) base;
        List<PDAnnotation> actuals = new ArrayList<>();
        for (int i = 0; i < annots.size(); i++) {
            COSBase item = annots.getObject(i);
            if (item == null) {
                continue;
            }
            PDAnnotation createdAnnotation = PDAnnotation.createAnnotation(item);
            if (annotationFilter.accept(createdAnnotation)) {
                actuals.add(createdAnnotation);
            }
        }
        return new COSArrayList<>(actuals, annots);
    }
    return new COSArrayList<>(page, COSName.ANNOTS);
}
Also used : COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) COSArray(org.apache.pdfbox.cos.COSArray) PDAnnotation(org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation) COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList) COSBase(org.apache.pdfbox.cos.COSBase)

Example 17 with COSArrayList

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

the class PDSeedValue method getDigestMethod.

/**
 * An array of names indicating acceptable digest algorithms to use when
 * signing. The value shall be one of <b>SHA1</b>, <b>SHA256</b>, <b>SHA384</b>,
 * <b>SHA512</b>, <b>RIPEMD160</b>. The default value is implementation-specific.
 *
 * @return the digest method that shall be used by the signature handler
 */
public List<String> getDigestMethod() {
    List<String> retval = null;
    COSArray fields = (COSArray) dictionary.getDictionaryObject(COSName.DIGEST_METHOD);
    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 18 with COSArrayList

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

the class PDSeedValue method getReasons.

/**
 * If the Reasons array is provided and {@link #isReasonRequired()} indicates that
 * Reasons is a required constraint, one of the reasons in the array shall be used
 * for the signature dictionary; otherwise signing shall not take place. If the
 * {@link #isReasonRequired()} indicates Reasons is an optional constraint, one of
 * the reasons in the array may be chose or a custom reason can be provided.
 *
 * @return the reasons that should be used by the signature handler
 */
public List<String> getReasons() {
    List<String> retval = null;
    COSArray fields = (COSArray) dictionary.getDictionaryObject(COSName.REASONS);
    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 19 with COSArrayList

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

the class PDAction method getNext.

/**
 * This will get the next action, or sequence of actions, to be performed after this one.
 * The value is either a single action dictionary or an array of action dictionaries
 * to be performed in order.
 *
 * @return The Next action or sequence of actions.
 */
public List<PDAction> getNext() {
    List<PDAction> retval = null;
    COSBase next = action.getDictionaryObject(COSName.NEXT);
    if (next instanceof COSDictionary) {
        PDAction pdAction = PDActionFactory.createAction((COSDictionary) next);
        retval = new COSArrayList<>(pdAction, next, action, COSName.NEXT);
    } else if (next instanceof COSArray) {
        COSArray array = (COSArray) next;
        List<PDAction> actions = new ArrayList<>();
        for (int i = 0; i < array.size(); i++) {
            actions.add(PDActionFactory.createAction((COSDictionary) array.getObject(i)));
        }
        retval = new COSArrayList<>(actions, array);
    }
    return retval;
}
Also used : COSArrayList(org.apache.pdfbox.pdmodel.common.COSArrayList) COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSArray(org.apache.pdfbox.cos.COSArray) COSBase(org.apache.pdfbox.cos.COSBase) List(java.util.List) 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