Search in sources :

Example 76 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDOptionalContentProperties method getD.

private COSDictionary getD() {
    COSBase base = this.dict.getDictionaryObject(COSName.D);
    if (base instanceof COSDictionary) {
        return (COSDictionary) base;
    }
    COSDictionary d = new COSDictionary();
    // Name optional but required for PDF/A-3
    d.setString(COSName.NAME, "Top");
    // D is required
    this.dict.setItem(COSName.D, d);
    return d;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 77 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDOptionalContentProperties method getOptionalContentGroups.

/**
 * Returns the collection of all optional content groups.
 * @return the optional content groups
 */
public Collection<PDOptionalContentGroup> getOptionalContentGroups() {
    Collection<PDOptionalContentGroup> coll = new ArrayList<PDOptionalContentGroup>();
    COSArray ocgs = getOCGs();
    for (COSBase base : ocgs) {
        coll.add(new PDOptionalContentGroup(toDictionary(base)));
    }
    return coll;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) ArrayList(java.util.ArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 78 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDImageXObject method getColorSpace.

@Override
public PDColorSpace getColorSpace() throws IOException {
    if (colorSpace == null) {
        COSBase cosBase = getCOSObject().getItem(COSName.COLORSPACE, COSName.CS);
        if (cosBase != null) {
            COSObject indirect = null;
            if (cosBase instanceof COSObject && resources != null && resources.getResourceCache() != null) {
                // PDFBOX-4022: use the resource cache because several images
                // might have the same colorspace indirect object.
                indirect = (COSObject) cosBase;
                colorSpace = resources.getResourceCache().getColorSpace(indirect);
                if (colorSpace != null) {
                    return colorSpace;
                }
            }
            colorSpace = PDColorSpace.create(cosBase, resources);
            if (indirect != null) {
                resources.getResourceCache().put(indirect, colorSpace);
            }
        } else if (isStencil()) {
            // stencil mask color space must be gray, it is often missing
            return PDDeviceGray.INSTANCE;
        } else {
            // an image without a color space is always broken
            throw new IOException("could not determine color space");
        }
    }
    return colorSpace;
}
Also used : COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase) IOException(java.io.IOException)

Example 79 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

the class PDExtendedGraphicsState method getFloatItem.

/**
 * This will get a float item from the dictionary.
 *
 * @param key The key to the item.
 *
 * @return The value for that item.
 */
private Float getFloatItem(COSName key) {
    Float retval = null;
    COSBase base = dict.getDictionaryObject(key);
    if (base instanceof COSNumber) {
        COSNumber value = (COSNumber) base;
        retval = value.floatValue();
    }
    return retval;
}
Also used : COSFloat(com.tom_roush.pdfbox.cos.COSFloat) COSNumber(com.tom_roush.pdfbox.cos.COSNumber) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 80 with COSBase

use of com.tom_roush.pdfbox.cos.COSBase in project PdfBox-Android by TomRoush.

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>(pdAction, next, action, COSName.NEXT);
    } else if (next instanceof COSArray) {
        COSArray array = (COSArray) next;
        List<PDAction> actions = new ArrayList<PDAction>();
        for (int i = 0; i < array.size(); i++) {
            actions.add(PDActionFactory.createAction((COSDictionary) array.getObject(i)));
        }
        retval = new COSArrayList<PDAction>(actions, array);
    }
    return retval;
}
Also used : COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) List(java.util.List) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) ArrayList(java.util.ArrayList)

Aggregations

COSBase (com.tom_roush.pdfbox.cos.COSBase)215 COSArray (com.tom_roush.pdfbox.cos.COSArray)108 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)68 COSName (com.tom_roush.pdfbox.cos.COSName)50 COSObject (com.tom_roush.pdfbox.cos.COSObject)42 IOException (java.io.IOException)34 COSString (com.tom_roush.pdfbox.cos.COSString)33 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)29 ArrayList (java.util.ArrayList)29 COSStream (com.tom_roush.pdfbox.cos.COSStream)20 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)14 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)11 HashMap (java.util.HashMap)11 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)10 Map (java.util.Map)10 List (java.util.List)9 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)8 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)7 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)7 PDFStreamParser (com.tom_roush.pdfbox.pdfparser.PDFStreamParser)6