Search in sources :

Example 71 with COSDictionary

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

the class PDResources method createKey.

/**
 * Returns a unique key for a new resource.
 */
private COSName createKey(COSName kind, String prefix) {
    COSDictionary dict = (COSDictionary) resources.getDictionaryObject(kind);
    if (dict == null) {
        return COSName.getPDFName(prefix + 1);
    }
    // find a unique key
    String key;
    int n = dict.keySet().size();
    do {
        ++n;
        key = prefix + n;
    } while (dict.containsKey(key));
    return COSName.getPDFName(key);
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 72 with COSDictionary

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

the class PDResources method put.

/**
 * Sets the value of a given named resource.
 */
private void put(COSName kind, COSName name, COSObjectable object) {
    COSDictionary dict = (COSDictionary) resources.getDictionaryObject(kind);
    if (dict == null) {
        dict = new COSDictionary();
        resources.setItem(kind, dict);
    }
    dict.setItem(name, object);
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 73 with COSDictionary

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

the class PDEmbeddedFile method setMacSubtype.

/**
 * Set the mac subtype.
 *
 * @param macSubtype The mac subtype.
 */
public void setMacSubtype(String macSubtype) {
    COSDictionary params = (COSDictionary) getCOSObject().getDictionaryObject(COSName.PARAMS);
    if (params == null && macSubtype != null) {
        params = new COSDictionary();
        getCOSObject().setItem(COSName.PARAMS, params);
    }
    if (params != null) {
        params.setEmbeddedString("Mac", "Subtype", macSubtype);
    }
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 74 with COSDictionary

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

the class PDEmbeddedFile method getMacCreator.

/**
 * Get the mac Creator.
 *
 * @return The mac Creator.
 */
public String getMacCreator() {
    String retval = null;
    COSDictionary params = (COSDictionary) getCOSObject().getDictionaryObject(COSName.PARAMS);
    if (params != null) {
        retval = params.getEmbeddedString("Mac", "Creator");
    }
    return retval;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary)

Example 75 with COSDictionary

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

the class COSDictionaryMap method convert.

/**
 * This will take a map<java.lang.String,com.tom_roush.pdfbox.pdmodel.COSObjectable>
 * and convert it into a COSDictionary.
 *
 * @param someMap A map containing COSObjectables
 *
 * @return A proper COSDictionary
 */
public static COSDictionary convert(Map<String, ?> someMap) {
    COSDictionary dic = new COSDictionary();
    for (Entry<String, ?> entry : someMap.entrySet()) {
        String name = entry.getKey();
        COSObjectable object = (COSObjectable) entry.getValue();
        dic.setItem(COSName.getPDFName(name), object.getCOSObject());
    }
    return dic;
}
Also used : COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) COSString(com.tom_roush.pdfbox.cos.COSString)

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