Search in sources :

Example 41 with COSBase

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

the class PDStream method setFilters.

/**
 * This will set the filters that are part of this stream.
 *
 * @param filters The filters that are part of this stream.
 */
public void setFilters(List<COSName> filters) {
    COSBase obj = COSArrayList.converterToCOSArray(filters);
    stream.setItem(COSName.FILTER, obj);
}
Also used : COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 42 with COSBase

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

the class PDStream method getFileFilters.

/**
 * This will get the list of filters that are associated with this stream.
 * Or null if there are none.
 *
 * @return A list of all encoding filters to apply to this stream.
 */
public List<String> getFileFilters() {
    List<String> retval = null;
    COSBase filters = stream.getDictionaryObject(COSName.F_FILTER);
    if (filters instanceof COSName) {
        COSName name = (COSName) filters;
        retval = new COSArrayList<String>(name.getName(), name, stream, COSName.F_FILTER);
    } else if (filters instanceof COSArray) {
        retval = COSArrayList.convertCOSNameCOSArrayToList((COSArray) filters);
    }
    return retval;
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 43 with COSBase

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

the class PDNumberTreeNode method getNumbers.

/**
 * This will return a map of numbers.  The key will be a java.lang.Integer, the value will
 * depend on where this class is being used.
 *
 * @return A map of COS objects.
 *
 * @throws IOException If there is a problem creating the values.
 */
public Map<Integer, COSObjectable> getNumbers() throws IOException {
    Map<Integer, COSObjectable> indices = null;
    COSBase numBase = node.getDictionaryObject(COSName.NUMS);
    if (numBase instanceof COSArray) {
        COSArray numbersArray = (COSArray) numBase;
        indices = new HashMap<Integer, COSObjectable>();
        for (int i = 0; i < numbersArray.size(); i += 2) {
            COSBase base = numbersArray.getObject(i);
            if (!(base instanceof COSInteger)) {
                Log.e("PdfBox-Android", "page labels ignored, index " + i + " should be a number, but is " + base);
                return null;
            }
            COSInteger key = (COSInteger) base;
            COSBase cosValue = numbersArray.getObject(i + 1);
            indices.put(key.intValue(), cosValue == null ? null : convertCOSToPD(cosValue));
        }
        indices = Collections.unmodifiableMap(indices);
    }
    return indices;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase)

Example 44 with COSBase

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

the class PDPage method getViewports.

/**
 * Get the viewports.
 *
 * @return a list of viewports or null if there is no /VP entry.
 */
public List<PDViewportDictionary> getViewports() {
    COSBase base = page.getDictionaryObject(COSName.VP);
    if (!(base instanceof COSArray)) {
        return null;
    }
    COSArray array = (COSArray) base;
    List<PDViewportDictionary> viewports = new ArrayList<PDViewportDictionary>();
    for (int i = 0; i < array.size(); ++i) {
        COSBase base2 = array.getObject(i);
        if (base2 instanceof COSDictionary) {
            viewports.add(new PDViewportDictionary((COSDictionary) base2));
        } else {
            Log.w("PdfBox-Android", "Array element " + base2 + " is skipped, must be a (viewport) dictionary");
        }
    }
    return viewports;
}
Also used : 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) PDViewportDictionary(com.tom_roush.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary)

Example 45 with COSBase

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

the class PDPage method getContentStreams.

/**
 * Returns the content streams which make up this page.
 *
 * @return content stream iterator
 */
public Iterator<PDStream> getContentStreams() {
    List<PDStream> streams = new ArrayList<PDStream>();
    COSBase base = page.getDictionaryObject(COSName.CONTENTS);
    if (base instanceof COSStream) {
        streams.add(new PDStream((COSStream) base));
    } else if (base instanceof COSArray && ((COSArray) base).size() > 0) {
        COSArray array = (COSArray) base;
        for (int i = 0; i < array.size(); i++) {
            COSStream stream = (COSStream) array.getObject(i);
            streams.add(new PDStream(stream));
        }
    }
    return streams.iterator();
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSArray(com.tom_roush.pdfbox.cos.COSArray) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream)

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