Search in sources :

Example 46 with COSBase

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

the class PDPage method getThreadBeads.

/**
 * This will get a list of PDThreadBead objects, which are article threads in the document. This
 * will return an empty list if there are no thread beads.
 *
 * @return A list of article threads on this page, never null. The returned list is backed by
 * the beads COSArray, so any adding or deleting in this list will change the document too.
 */
public List<PDThreadBead> getThreadBeads() {
    COSArray beads = (COSArray) page.getDictionaryObject(COSName.B);
    if (beads == null) {
        beads = new COSArray();
    }
    List<PDThreadBead> pdObjects = new ArrayList<PDThreadBead>();
    for (int i = 0; i < beads.size(); i++) {
        COSBase base = beads.getObject(i);
        PDThreadBead bead = null;
        // in some cases the bead is null
        if (base instanceof COSDictionary) {
            bead = new PDThreadBead((COSDictionary) base);
        }
        pdObjects.add(bead);
    }
    return new COSArrayList<PDThreadBead>(pdObjects, beads);
}
Also used : COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDThreadBead(com.tom_roush.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead)

Example 47 with COSBase

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

the class PDDocumentCatalog method getOutputIntents.

/**
 * Get the list of OutputIntents defined in the document.
 *
 * @return The list of PDOutputIntent
 */
public List<PDOutputIntent> getOutputIntents() {
    List<PDOutputIntent> retval = new ArrayList<PDOutputIntent>();
    COSArray array = (COSArray) root.getDictionaryObject(COSName.OUTPUT_INTENTS);
    if (array != null) {
        for (COSBase cosBase : array) {
            if (cosBase instanceof COSObject) {
                cosBase = ((COSObject) cosBase).getObject();
            }
            PDOutputIntent oi = new PDOutputIntent((COSDictionary) cosBase);
            retval.add(oi);
        }
    }
    return retval;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSObject(com.tom_roush.pdfbox.cos.COSObject) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDOutputIntent(com.tom_roush.pdfbox.pdmodel.graphics.color.PDOutputIntent)

Example 48 with COSBase

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

the class PDPageTree method getInheritableAttribute.

/**
 * Returns the given attribute, inheriting from parent tree nodes if necessary.
 *
 * @param node page object
 * @param key the key to look up
 * @return COS value for the given key
 */
public static COSBase getInheritableAttribute(COSDictionary node, COSName key) {
    COSBase value = node.getDictionaryObject(key);
    if (value != null) {
        return value;
    }
    COSBase base = node.getDictionaryObject(COSName.PARENT, COSName.P);
    if (base instanceof COSDictionary) {
        COSDictionary parent = (COSDictionary) base;
        if (COSName.PAGES.equals(parent.getDictionaryObject(COSName.TYPE))) {
            return getInheritableAttribute(parent, key);
        }
    }
    return null;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 49 with COSBase

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

the class PDResources method add.

/**
 * Adds the given resource if it does not already exist.
 */
private COSName add(COSName kind, String prefix, COSObjectable object) {
    // return the existing key if the item exists already
    COSDictionary dict = (COSDictionary) resources.getDictionaryObject(kind);
    if (dict != null && dict.containsValue(object.getCOSObject())) {
        return dict.getKeyForValue(object.getCOSObject());
    }
    // AcroForm default resources of a loaded PDF.
    if (dict != null && COSName.FONT.equals(kind)) {
        for (Map.Entry<COSName, COSBase> entry : dict.entrySet()) {
            if (entry.getValue() instanceof COSObject && object.getCOSObject() == ((COSObject) entry.getValue()).getObject()) {
                return entry.getKey();
            }
        }
    }
    // add the item with a new key
    COSName name = createKey(kind, prefix);
    put(kind, name, object);
    return name;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSName(com.tom_roush.pdfbox.cos.COSName) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase) HashMap(java.util.HashMap) Map(java.util.Map)

Example 50 with COSBase

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

the class PDResources method isImageXObject.

/**
 * Tells whether the XObject resource with the given name is an image.
 *
 * @param name Name of the XObject resource.
 * @return true if it is an image XObject, false if not.
 */
public boolean isImageXObject(COSName name) {
    // get the instance
    COSBase value = get(COSName.XOBJECT, name);
    if (value == null) {
        return false;
    } else if (value instanceof COSObject) {
        value = ((COSObject) value).getObject();
    }
    if (!(value instanceof COSStream)) {
        return false;
    }
    COSStream stream = (COSStream) value;
    return COSName.IMAGE.equals(stream.getCOSName(COSName.SUBTYPE));
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase)

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