Search in sources :

Example 61 with COSDictionary

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

the class PDDocumentCatalog method getThreads.

/**
 * Returns the document's article threads.
 *
 * @return a list containing all article threads.
 */
public List<PDThread> getThreads() {
    COSArray array = (COSArray) root.getDictionaryObject(COSName.THREADS);
    if (array == null) {
        array = new COSArray();
        root.setItem(COSName.THREADS, array);
    }
    List<PDThread> pdObjects = new ArrayList<PDThread>();
    for (int i = 0; i < array.size(); i++) {
        pdObjects.add(new PDThread((COSDictionary) array.getObject(i)));
    }
    return new COSArrayList<PDThread>(pdObjects, array);
}
Also used : COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDThread(com.tom_roush.pdfbox.pdmodel.interactive.pagenavigation.PDThread) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList)

Example 62 with COSDictionary

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

the class PDDocumentNameDictionary method getJavaScript.

/**
 * Get the document level javascript entries. The values in this name tree
 * will be PDTextStream objects.
 *
 * @return The document level named javascript.
 */
public PDJavascriptNameTreeNode getJavaScript() {
    PDJavascriptNameTreeNode retval = null;
    COSDictionary dic = (COSDictionary) nameDictionary.getDictionaryObject(COSName.JAVA_SCRIPT);
    if (dic != null) {
        retval = new PDJavascriptNameTreeNode(dic);
    }
    return retval;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 63 with COSDictionary

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

the class PDPageTree method remove.

/**
 * Removes the given COS page.
 */
private void remove(COSDictionary node) {
    // remove from parent's kids
    COSDictionary parent = (COSDictionary) node.getDictionaryObject(COSName.PARENT, COSName.P);
    COSArray kids = (COSArray) parent.getDictionaryObject(COSName.KIDS);
    if (kids.removeObject(node)) {
        // update ancestor counts
        do {
            node = (COSDictionary) node.getDictionaryObject(COSName.PARENT, COSName.P);
            if (node != null) {
                node.setInt(COSName.COUNT, node.getInt(COSName.COUNT) - 1);
            }
        } while (node != null);
    }
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSArray(com.tom_roush.pdfbox.cos.COSArray)

Example 64 with COSDictionary

use of com.tom_roush.pdfbox.cos.COSDictionary 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 65 with COSDictionary

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

the class PDPageTree method get.

/**
 * Returns the page at the given index.
 *
 * @param index zero-based index
 *
 * @return the page at the given index.
 */
public PDPage get(int index) {
    COSDictionary dict = get(index + 1, root, 0);
    sanitizeType(dict);
    ResourceCache resourceCache = document != null ? document.getResourceCache() : null;
    return new PDPage(dict, resourceCache);
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Aggregations

COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)221 COSArray (com.tom_roush.pdfbox.cos.COSArray)68 COSBase (com.tom_roush.pdfbox.cos.COSBase)68 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)24 COSName (com.tom_roush.pdfbox.cos.COSName)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)22 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)15 HashMap (java.util.HashMap)14 COSStream (com.tom_roush.pdfbox.cos.COSStream)13 Map (java.util.Map)12 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)10 COSString (com.tom_roush.pdfbox.cos.COSString)7 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)6 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 List (java.util.List)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 Test (org.junit.Test)5