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;
}
}
Aggregations