Search in sources :

Example 61 with COSNumber

use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.

the class COSUtils method getAsInteger.

/**
 * Return the COSBase object as Integer if the COSBase object is an instance of COSInteger or a reference to a
 * COSInteger object. In other cases, this method returns null;
 *
 * @param cbase the object to get.
 * @param cDoc the document.
 * @return the object as Integer if the object is a COSInteger or a reference to it. Returns null otherwise.
 */
public static Integer getAsInteger(COSBase cbase, COSDocument cDoc) {
    if (cbase instanceof COSObject) {
        COSObjectKey key = new COSObjectKey((COSObject) cbase);
        COSObject obj = cDoc.getObjectFromPool(key);
        if (obj == null) {
            return null;
        } else if (obj.getObject() instanceof COSNumber) {
            return ((COSNumber) obj.getObject()).intValue();
        } else {
            return null;
        }
    } else if (cbase instanceof COSNumber) {
        return ((COSNumber) cbase).intValue();
    } else {
        return null;
    }
}
Also used : COSObjectKey(org.apache.pdfbox.cos.COSObjectKey) COSObject(org.apache.pdfbox.cos.COSObject) COSNumber(org.apache.pdfbox.cos.COSNumber)

Aggregations

COSNumber (org.apache.pdfbox.cos.COSNumber)61 COSBase (org.apache.pdfbox.cos.COSBase)29 MissingOperandException (org.apache.pdfbox.contentstream.operator.MissingOperandException)18 COSArray (org.apache.pdfbox.cos.COSArray)18 COSInteger (org.apache.pdfbox.cos.COSInteger)10 Point2D (java.awt.geom.Point2D)6 IOException (java.io.IOException)6 COSObject (org.apache.pdfbox.cos.COSObject)5 PDBorderStyleDictionary (org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)5 ArrayList (java.util.ArrayList)4 COSDictionary (org.apache.pdfbox.cos.COSDictionary)4 COSName (org.apache.pdfbox.cos.COSName)4 COSObjectKey (org.apache.pdfbox.cos.COSObjectKey)4 PDFont (org.apache.pdfbox.pdmodel.font.PDFont)4 COSFloat (org.apache.pdfbox.cos.COSFloat)3 COSStream (org.apache.pdfbox.cos.COSStream)2 PDRectangle (org.apache.pdfbox.pdmodel.common.PDRectangle)2 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)2 Matrix (org.apache.pdfbox.util.Matrix)2 Paint (java.awt.Paint)1