Search in sources :

Example 1 with COSInteger

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

the class BaseParser method parseCOSArray.

/**
 * This will parse a PDF array object.
 *
 * @return The parsed PDF array.
 *
 * @throws IOException If there is an error parsing the stream.
 */
protected COSArray parseCOSArray() throws IOException {
    long startPosition = seqSource.getPosition();
    readExpectedChar('[');
    COSArray po = new COSArray();
    COSBase pbo;
    skipSpaces();
    int i;
    while (((i = seqSource.peek()) > 0) && ((char) i != ']')) {
        pbo = parseDirObject();
        if (pbo instanceof COSObject) {
            // We have to check if the expected values are there or not PDFBOX-385
            if (po.size() > 0 && po.get(po.size() - 1) instanceof COSInteger) {
                COSInteger genNumber = (COSInteger) po.remove(po.size() - 1);
                if (po.size() > 0 && po.get(po.size() - 1) instanceof COSInteger) {
                    COSInteger number = (COSInteger) po.remove(po.size() - 1);
                    COSObjectKey key = new COSObjectKey(number.longValue(), genNumber.intValue());
                    pbo = getObjectFromPool(key);
                } else {
                    // the object reference is somehow wrong
                    pbo = null;
                }
            } else {
                pbo = null;
            }
        }
        if (pbo != null) {
            po.add(pbo);
        } else {
            // it could be a bad object in the array which is just skipped
            Log.w("PdfBox-Android", "Corrupt object reference at offset " + seqSource.getPosition() + ", start offset: " + startPosition);
            // This could also be an "endobj" or "endstream" which means we can assume that
            // the array has ended.
            String isThisTheEnd = readString();
            seqSource.unread(isThisTheEnd.getBytes(ISO_8859_1));
            if (ENDOBJ_STRING.equals(isThisTheEnd) || ENDSTREAM_STRING.equals(isThisTheEnd)) {
                return po;
            }
        }
        skipSpaces();
    }
    // read ']'
    seqSource.read();
    skipSpaces();
    return po;
}
Also used : COSObjectKey(com.tom_roush.pdfbox.cos.COSObjectKey) COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSObject(com.tom_roush.pdfbox.cos.COSObject) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 2 with COSInteger

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

the class ContentStreamWriter method writeObject.

private void writeObject(Object o) throws IOException {
    if (o instanceof COSString) {
        COSWriter.writeString((COSString) o, output);
        output.write(SPACE);
    } else if (o instanceof COSFloat) {
        ((COSFloat) o).writePDF(output);
        output.write(SPACE);
    } else if (o instanceof COSInteger) {
        ((COSInteger) o).writePDF(output);
        output.write(SPACE);
    } else if (o instanceof COSBoolean) {
        ((COSBoolean) o).writePDF(output);
        output.write(SPACE);
    } else if (o instanceof COSName) {
        ((COSName) o).writePDF(output);
        output.write(SPACE);
    } else if (o instanceof COSArray) {
        COSArray array = (COSArray) o;
        output.write(COSWriter.ARRAY_OPEN);
        for (int i = 0; i < array.size(); i++) {
            writeObject(array.get(i));
            output.write(SPACE);
        }
        output.write(COSWriter.ARRAY_CLOSE);
    } else if (o instanceof COSDictionary) {
        COSDictionary obj = (COSDictionary) o;
        output.write(COSWriter.DICT_OPEN);
        for (Map.Entry<COSName, COSBase> entry : obj.entrySet()) {
            if (entry.getValue() != null) {
                writeObject(entry.getKey());
                output.write(SPACE);
                writeObject(entry.getValue());
                output.write(SPACE);
            }
        }
        output.write(COSWriter.DICT_CLOSE);
        output.write(SPACE);
    } else if (o instanceof Operator) {
        Operator op = (Operator) o;
        if (op.getName().equals(OperatorName.BEGIN_INLINE_IMAGE)) {
            output.write(OperatorName.BEGIN_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1));
            COSDictionary dic = op.getImageParameters();
            for (COSName key : dic.keySet()) {
                Object value = dic.getDictionaryObject(key);
                key.writePDF(output);
                output.write(SPACE);
                writeObject(value);
                output.write(EOL);
            }
            output.write(OperatorName.BEGIN_INLINE_IMAGE_DATA.getBytes(Charsets.ISO_8859_1));
            output.write(EOL);
            output.write(op.getImageData());
            output.write(EOL);
            output.write(OperatorName.END_INLINE_IMAGE.getBytes(Charsets.ISO_8859_1));
            output.write(EOL);
        } else {
            output.write(op.getName().getBytes(Charsets.ISO_8859_1));
            output.write(EOL);
        }
    } else {
        throw new IOException("Error:Unknown type in content stream:" + o);
    }
}
Also used : Operator(com.tom_roush.pdfbox.contentstream.operator.Operator) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) IOException(java.io.IOException) COSBoolean(com.tom_roush.pdfbox.cos.COSBoolean) COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString) Map(java.util.Map) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 3 with COSInteger

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

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

the class FDFField method setSetWidgetFieldFlags.

/**
 * This will get the widget field flags that are associated with this field. The SetF entry in the FDF field
 * dictionary.
 *
 * @param ff The new value for the "set widget field flags".
 */
public void setSetWidgetFieldFlags(Integer ff) {
    COSInteger value = null;
    if (ff != null) {
        value = COSInteger.get(ff);
    }
    field.setItem(COSName.SET_F, value);
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger)

Example 5 with COSInteger

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

the class FDFField method setClearWidgetFieldFlags.

/**
 * This will get the field flags that are associated with this field. The ClrF entry in the FDF field dictionary.
 *
 * @param ff The new value for the "clear widget field flags".
 */
public void setClearWidgetFieldFlags(Integer ff) {
    COSInteger value = null;
    if (ff != null) {
        value = COSInteger.get(ff);
    }
    field.setItem(COSName.CLR_F, value);
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger)

Aggregations

COSInteger (com.tom_roush.pdfbox.cos.COSInteger)17 COSBase (com.tom_roush.pdfbox.cos.COSBase)9 COSArray (com.tom_roush.pdfbox.cos.COSArray)7 COSName (com.tom_roush.pdfbox.cos.COSName)4 COSObject (com.tom_roush.pdfbox.cos.COSObject)4 COSString (com.tom_roush.pdfbox.cos.COSString)3 COSBoolean (com.tom_roush.pdfbox.cos.COSBoolean)2 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)2 COSFloat (com.tom_roush.pdfbox.cos.COSFloat)2 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)2 COSObjectKey (com.tom_roush.pdfbox.cos.COSObjectKey)2 IOException (java.io.IOException)2 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1 COSObjectable (com.tom_roush.pdfbox.pdmodel.common.COSObjectable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1