Search in sources :

Example 1 with COSFloat

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

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

the class PDAnnotationMarkup method setRectDifferences.

/**
 * This will set the difference between the annotations "outer" rectangle defined by
 * /Rect and the border.
 *
 * @param differenceLeft left difference from the annotations /Rect entry
 * @param differenceTop top difference from the annotations /Rect entry
 * @param differenceRight right difference from  the annotations /Rect entry
 * @param differenceBottom bottom difference from the annotations /Rect entry
 */
public void setRectDifferences(float differenceLeft, float differenceTop, float differenceRight, float differenceBottom) {
    COSArray margins = new COSArray();
    margins.add(new COSFloat(differenceLeft));
    margins.add(new COSFloat(differenceTop));
    margins.add(new COSFloat(differenceRight));
    margins.add(new COSFloat(differenceBottom));
    getCOSObject().setItem(COSName.RD, margins);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 3 with COSFloat

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

the class PDAnnotationSquareCircle method setRectDifferences.

/**
 * This will set the difference between the annotations "outer" rectangle defined by
 * /Rect and the border.
 *
 * @param differenceLeft left difference from the annotations /Rect entry
 * @param differenceTop top difference from the annotations /Rect entry
 * @param differenceRight right difference from  the annotations /Rect entry
 * @param differenceBottom bottom difference from the annotations /Rect entry
 */
public void setRectDifferences(float differenceLeft, float differenceTop, float differenceRight, float differenceBottom) {
    COSArray margins = new COSArray();
    margins.add(new COSFloat(differenceLeft));
    margins.add(new COSFloat(differenceTop));
    margins.add(new COSFloat(differenceRight));
    margins.add(new COSFloat(differenceBottom));
    getCOSObject().setItem(COSName.RD, margins);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Example 4 with COSFloat

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

the class MatrixTest method testPdfbox2872.

/**
 * Test of PDFBOX-2872 bug
 */
@Test
public void testPdfbox2872() {
    Matrix m = new Matrix(2, 4, 5, 8, 2, 0);
    COSArray toCOSArray = m.toCOSArray();
    assertEquals(new COSFloat(2), toCOSArray.get(0));
    assertEquals(new COSFloat(4), toCOSArray.get(1));
    assertEquals(new COSFloat(5), toCOSArray.get(2));
    assertEquals(new COSFloat(8), toCOSArray.get(3));
    assertEquals(new COSFloat(2), toCOSArray.get(4));
    assertEquals(new COSFloat(0), toCOSArray.get(5));
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSFloat(com.tom_roush.pdfbox.cos.COSFloat) Test(org.junit.Test)

Example 5 with COSFloat

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

the class PDPage method setTransition.

/**
 * Convenient method to set a transition and the display duration
 *
 * @param transition The new transition to set on this page.
 * @param duration The maximum length of time, in seconds, that the page shall be displayed during presentations
 * before the viewer application shall automatically advance to the next page.
 */
public void setTransition(PDTransition transition, float duration) {
    page.setItem(COSName.TRANS, transition);
    page.setItem(COSName.DUR, new COSFloat(duration));
}
Also used : COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Aggregations

COSFloat (com.tom_roush.pdfbox.cos.COSFloat)20 COSArray (com.tom_roush.pdfbox.cos.COSArray)16 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 COSBoolean (com.tom_roush.pdfbox.cos.COSBoolean)2 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)2 COSName (com.tom_roush.pdfbox.cos.COSName)2 COSString (com.tom_roush.pdfbox.cos.COSString)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)1 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)1 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1