Search in sources :

Example 36 with COSNumber

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

the class BaseParser method parseCOSDictionaryValue.

/**
 * This will parse a PDF dictionary value.
 *
 * @return The parsed Dictionary object.
 *
 * @throws IOException If there is an error parsing the dictionary object.
 */
private COSBase parseCOSDictionaryValue() throws IOException {
    long numOffset = seqSource.getPosition();
    COSBase value = parseDirObject();
    skipSpaces();
    // proceed if the given object is a number and the following is a number as well
    if (!(value instanceof COSNumber) || !isDigit()) {
        return value;
    }
    // read the remaining information of the object number
    long genOffset = seqSource.getPosition();
    COSBase generationNumber = parseDirObject();
    skipSpaces();
    readExpectedChar('R');
    if (!(value instanceof COSInteger)) {
        throw new IOException("expected number, actual=" + value + " at offset " + numOffset);
    }
    if (!(generationNumber instanceof COSInteger)) {
        throw new IOException("expected number, actual=" + value + " at offset " + genOffset);
    }
    COSObjectKey key = new COSObjectKey(((COSInteger) value).longValue(), ((COSInteger) generationNumber).intValue());
    // dereference the object
    return getObjectFromPool(key);
}
Also used : COSObjectKey(org.apache.pdfbox.cos.COSObjectKey) COSInteger(org.apache.pdfbox.cos.COSInteger) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase) IOException(java.io.IOException)

Example 37 with COSNumber

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

the class SetLineWidth method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.size() < 1) {
        throw new MissingOperandException(operator, arguments);
    }
    COSNumber width = (COSNumber) arguments.get(0);
    context.getGraphicsState().setLineWidth(width.floatValue());
}
Also used : MissingOperandException(org.apache.pdfbox.contentstream.operator.MissingOperandException) COSNumber(org.apache.pdfbox.cos.COSNumber)

Example 38 with COSNumber

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

the class SetMatrix method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws MissingOperandException {
    if (arguments.size() < 6) {
        throw new MissingOperandException(operator, arguments);
    }
    if (!checkArrayTypesClass(arguments, COSNumber.class)) {
        return;
    }
    COSNumber a = (COSNumber) arguments.get(0);
    COSNumber b = (COSNumber) arguments.get(1);
    COSNumber c = (COSNumber) arguments.get(2);
    COSNumber d = (COSNumber) arguments.get(3);
    COSNumber e = (COSNumber) arguments.get(4);
    COSNumber f = (COSNumber) arguments.get(5);
    Matrix matrix = new Matrix(a.floatValue(), b.floatValue(), c.floatValue(), d.floatValue(), e.floatValue(), f.floatValue());
    context.setTextMatrix(matrix);
    context.setTextLineMatrix(matrix.clone());
}
Also used : Matrix(org.apache.pdfbox.util.Matrix) MissingOperandException(org.apache.pdfbox.contentstream.operator.MissingOperandException) COSNumber(org.apache.pdfbox.cos.COSNumber)

Example 39 with COSNumber

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

the class MoveText method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws MissingOperandException {
    if (arguments.size() < 2) {
        throw new MissingOperandException(operator, arguments);
    }
    Matrix textLineMatrix = context.getTextLineMatrix();
    if (textLineMatrix == null) {
        LOG.warn("TextLineMatrix is null, " + getName() + " operator will be ignored");
        return;
    }
    COSBase base0 = arguments.get(0);
    COSBase base1 = arguments.get(1);
    if (!(base0 instanceof COSNumber)) {
        return;
    }
    if (!(base1 instanceof COSNumber)) {
        return;
    }
    COSNumber x = (COSNumber) base0;
    COSNumber y = (COSNumber) base1;
    Matrix matrix = new Matrix(1, 0, 0, 1, x.floatValue(), y.floatValue());
    textLineMatrix.concatenate(matrix);
    context.setTextMatrix(textLineMatrix.clone());
}
Also used : Matrix(org.apache.pdfbox.util.Matrix) MissingOperandException(org.apache.pdfbox.contentstream.operator.MissingOperandException) COSNumber(org.apache.pdfbox.cos.COSNumber) COSBase(org.apache.pdfbox.cos.COSBase)

Example 40 with COSNumber

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

the class SetCharSpacing method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.isEmpty()) {
        throw new MissingOperandException(operator, arguments);
    }
    // there are some documents which are incorrectly structured, and have
    // a wrong number of arguments to this, so we will assume the last argument
    // in the list
    Object charSpacing = arguments.get(arguments.size() - 1);
    if (charSpacing instanceof COSNumber) {
        COSNumber characterSpacing = (COSNumber) charSpacing;
        context.getGraphicsState().getTextState().setCharacterSpacing(characterSpacing.floatValue());
    }
}
Also used : MissingOperandException(org.apache.pdfbox.contentstream.operator.MissingOperandException) 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