Search in sources :

Example 31 with COSString

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

the class COSArrayList method set.

/**
 * {@inheritDoc}
 */
@Override
public E set(int index, E element) {
    if (element instanceof String) {
        COSString item = new COSString((String) element);
        if (parentDict != null && index == 0) {
            parentDict.setItem(dictKey, item);
        }
        array.set(index, item);
    } else {
        if (parentDict != null && index == 0) {
            parentDict.setItem(dictKey, ((COSObjectable) element).getCOSObject());
        }
        array.set(index, ((COSObjectable) element).getCOSObject());
    }
    return actual.set(index, element);
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 32 with COSString

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

the class COSArrayList method add.

/**
 * {@inheritDoc}
 */
@Override
public boolean add(E o) {
    // in the dictionary from a single item to an array.
    if (parentDict != null) {
        parentDict.setItem(dictKey, array);
        // clear the parent dict so it doesn't happen again, there might be
        // a usecase for keeping the parentDict around but not now.
        parentDict = null;
    }
    // string is a special case because we can't subclass to be COSObjectable
    if (o instanceof String) {
        array.add(new COSString((String) o));
    } else {
        if (array != null) {
            array.add(((COSObjectable) o).getCOSObject());
        }
    }
    return actual.add(o);
}
Also used : COSString(com.tom_roush.pdfbox.cos.COSString) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 33 with COSString

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

the class COSDictionaryMap method convertBasicTypesToMap.

/**
 * This will take a COS dictionary and convert it into COSDictionaryMap.  All cos
 * objects will be converted to their primitive form.
 *
 * @param map The COS mappings.
 * @return A standard java map.
 * @throws IOException If there is an error during the conversion.
 */
public static COSDictionaryMap<String, Object> convertBasicTypesToMap(COSDictionary map) throws IOException {
    COSDictionaryMap<String, Object> retval = null;
    if (map != null) {
        Map<String, Object> actualMap = new HashMap<String, Object>();
        for (COSName key : map.keySet()) {
            COSBase cosObj = map.getDictionaryObject(key);
            Object actualObject = null;
            if (cosObj instanceof COSString) {
                actualObject = ((COSString) cosObj).getString();
            } else if (cosObj instanceof COSInteger) {
                actualObject = ((COSInteger) cosObj).intValue();
            } else if (cosObj instanceof COSName) {
                actualObject = ((COSName) cosObj).getName();
            } else if (cosObj instanceof COSFloat) {
                actualObject = ((COSFloat) cosObj).floatValue();
            } else if (cosObj instanceof COSBoolean) {
                actualObject = ((COSBoolean) cosObj).getValue() ? Boolean.TRUE : Boolean.FALSE;
            } else {
                throw new IOException("Error:unknown type of object to convert:" + cosObj);
            }
            actualMap.put(key.getName(), actualObject);
        }
        retval = new COSDictionaryMap<String, Object>(actualMap, map);
    }
    return retval;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSName(com.tom_roush.pdfbox.cos.COSName) HashMap(java.util.HashMap) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString) COSBoolean(com.tom_roush.pdfbox.cos.COSBoolean) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 34 with COSString

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

the class PDNameTreeNode method getNames.

/**
 * This will return a map of names on this level. The key will be a string,
 * and the value will depend on where this class is being used.
 *
 * @return ordered map of COS objects or <code>null</code> if the dictionary
 * contains no 'Names' entry on this level.
 *
 * @throws IOException If there is an error while creating the sub types.
 * @see #getKids()
 */
public Map<String, T> getNames() throws IOException {
    COSArray namesArray = (COSArray) node.getDictionaryObject(COSName.NAMES);
    if (namesArray != null) {
        Map<String, T> names = new LinkedHashMap<String, T>();
        for (int i = 0; i < namesArray.size(); i += 2) {
            COSString key = (COSString) namesArray.getObject(i);
            COSBase cosValue = namesArray.getObject(i + 1);
            names.put(key.getString(), convertCOSToPD(cosValue));
        }
        return Collections.unmodifiableMap(names);
    } else {
        return null;
    }
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString) COSString(com.tom_roush.pdfbox.cos.COSString) LinkedHashMap(java.util.LinkedHashMap)

Example 35 with COSString

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

the class AppearanceGeneratorHelper method getWidgetDefaultAppearanceString.

private PDDefaultAppearanceString getWidgetDefaultAppearanceString(PDAnnotationWidget widget) throws IOException {
    COSString da = (COSString) widget.getCOSObject().getDictionaryObject(COSName.DA);
    PDResources dr = field.getAcroForm().getDefaultResources();
    return new PDDefaultAppearanceString(da, dr);
}
Also used : PDResources(com.tom_roush.pdfbox.pdmodel.PDResources) COSString(com.tom_roush.pdfbox.cos.COSString)

Aggregations

COSString (com.tom_roush.pdfbox.cos.COSString)65 COSArray (com.tom_roush.pdfbox.cos.COSArray)33 COSBase (com.tom_roush.pdfbox.cos.COSBase)24 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)5 COSName (com.tom_roush.pdfbox.cos.COSName)5 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)4 Map (java.util.Map)4 COSBoolean (com.tom_roush.pdfbox.cos.COSBoolean)2 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)2 MessageDigest (java.security.MessageDigest)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1