Search in sources :

Example 11 with COSNumber

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

the class PDCalGray method getGamma.

/**
 * This will get the gamma value. If none is present then the default of 1
 * will be returned.
 *
 * @return The gamma value.
 */
public float getGamma() {
    float retval = 1.0f;
    COSNumber gamma = (COSNumber) dictionary.getDictionaryObject(COSName.GAMMA);
    if (gamma != null) {
        retval = gamma.floatValue();
    }
    return retval;
}
Also used : COSNumber(org.apache.pdfbox.cos.COSNumber)

Example 12 with COSNumber

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

the class PDAnnotation method getRectangle.

/**
 * The annotation rectangle, defining the location of the annotation on the page in default user space units. This
 * is usually required and should not return null on valid PDF documents. But where this is a parent form field with
 * children, such as radio button collections then the rectangle will be null.
 *
 * @return The Rect value of this annotation.
 */
public PDRectangle getRectangle() {
    COSArray rectArray = (COSArray) dictionary.getDictionaryObject(COSName.RECT);
    PDRectangle rectangle = null;
    if (rectArray != null) {
        if (rectArray.size() == 4 && rectArray.getObject(0) instanceof COSNumber && rectArray.getObject(1) instanceof COSNumber && rectArray.getObject(2) instanceof COSNumber && rectArray.getObject(3) instanceof COSNumber) {
            rectangle = new PDRectangle(rectArray);
        } else {
            LOG.warn(rectArray + " is not a rectangle array, returning null");
        }
    }
    return rectangle;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSNumber(org.apache.pdfbox.cos.COSNumber) PDRectangle(org.apache.pdfbox.pdmodel.common.PDRectangle)

Example 13 with COSNumber

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

the class PDExtendedGraphicsState method getLineDashPattern.

/**
 * This will get the dash pattern.
 *
 * @return null or the D value in the dictionary.
 */
public PDLineDashPattern getLineDashPattern() {
    PDLineDashPattern retval = null;
    COSBase dp = dict.getDictionaryObject(COSName.D);
    if (dp instanceof COSArray && ((COSArray) dp).size() == 2) {
        COSBase dashArray = ((COSArray) dp).getObject(0);
        COSBase phase = ((COSArray) dp).getObject(1);
        if (dashArray instanceof COSArray && phase instanceof COSNumber) {
            retval = new PDLineDashPattern((COSArray) dashArray, ((COSNumber) phase).intValue());
        }
    }
    return retval;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSNumber(org.apache.pdfbox.cos.COSNumber) PDLineDashPattern(org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern) COSBase(org.apache.pdfbox.cos.COSBase)

Example 14 with COSNumber

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

the class PDAcroForm method getQ.

/**
 * This will get the document-wide default value for the quadding/justification of variable text
 * fields.
 * <p>
 * 0 - Left(default)<br>
 * 1 - Centered<br>
 * 2 - Right<br>
 * See the QUADDING constants of {@link PDVariableText}.
 *
 * @return The justification of the variable text fields.
 */
public int getQ() {
    int retval = 0;
    COSNumber number = (COSNumber) dictionary.getDictionaryObject(COSName.Q);
    if (number != null) {
        retval = number.intValue();
    }
    return retval;
}
Also used : COSNumber(org.apache.pdfbox.cos.COSNumber)

Example 15 with COSNumber

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

the class PDPolygonAppearanceHandler method getLineWidth.

/**
 * Get the line with of the border.
 *
 * Get the width of the line used to draw a border around the annotation.
 * This may either be specified by the annotation dictionaries Border
 * setting or by the W entry in the BS border style dictionary. If both are
 * missing the default width is 1.
 *
 * @return the line width
 */
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
    PDAnnotationPolygon annotation = (PDAnnotationPolygon) getAnnotation();
    PDBorderStyleDictionary bs = annotation.getBorderStyle();
    if (bs != null) {
        return bs.getWidth();
    } else {
        COSArray borderCharacteristics = annotation.getBorder();
        if (borderCharacteristics.size() >= 3) {
            COSBase base = borderCharacteristics.getObject(2);
            if (base instanceof COSNumber) {
                return ((COSNumber) base).floatValue();
            }
        }
    }
    return 1;
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) PDAnnotationPolygon(org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationPolygon) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase) PDBorderStyleDictionary(org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary)

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