Search in sources :

Example 31 with COSName

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

the class PDFRenderer method hasBlendMode.

private boolean hasBlendMode(PDPage page) {
    // check the current resources for blend modes
    PDResources resources = page.getResources();
    if (resources == null) {
        return false;
    }
    for (COSName name : resources.getExtGStateNames()) {
        PDExtendedGraphicsState extGState = resources.getExtGState(name);
        if (extGState == null) {
            // see PDFBOX-3950-23EGDHXSBBYQLKYOKGZUOVYVNE675PRD.pdf
            continue;
        }
        BlendMode blendMode = extGState.getBlendMode();
        if (blendMode != BlendMode.NORMAL) {
            return true;
        }
    }
    return false;
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) PDExtendedGraphicsState(com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState) BlendMode(com.tom_roush.pdfbox.pdmodel.graphics.blend.BlendMode) PDResources(com.tom_roush.pdfbox.pdmodel.PDResources)

Example 32 with COSName

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

the class PDField method importFDF.

/**
 * This will import a fdf field from a fdf document.
 *
 * @param fdfField The fdf field to import.
 * @throws IOException If there is an error importing the data for this field.
 */
void importFDF(FDFField fdfField) throws IOException {
    COSBase fieldValue = fdfField.getCOSValue();
    if (fieldValue != null && this instanceof PDTerminalField) {
        PDTerminalField currentField = (PDTerminalField) this;
        if (fieldValue instanceof COSName) {
            currentField.setValue(((COSName) fieldValue).getName());
        } else if (fieldValue instanceof COSString) {
            currentField.setValue(((COSString) fieldValue).getString());
        } else if (fieldValue instanceof COSStream) {
            currentField.setValue(((COSStream) fieldValue).toTextString());
        } else if (fieldValue instanceof COSArray && this instanceof PDChoice) {
            ((PDChoice) this).setValue(COSArrayList.convertCOSStringCOSArrayToList((COSArray) fieldValue));
        } else {
            throw new IOException("Error:Unknown type for field import" + fieldValue);
        }
    } else if (fieldValue != null) {
        dictionary.setItem(COSName.V, fieldValue);
    }
    Integer ff = fdfField.getFieldFlags();
    if (ff != null) {
        setFieldFlags(ff);
    } else {
        // these are suppose to be ignored if the Ff is set.
        Integer setFf = fdfField.getSetFieldFlags();
        int fieldFlags = getFieldFlags();
        if (setFf != null) {
            int setFfInt = setFf;
            fieldFlags = fieldFlags | setFfInt;
            setFieldFlags(fieldFlags);
        }
        Integer clrFf = fdfField.getClearFieldFlags();
        if (clrFf != null) {
            // we have to clear the bits of the document fields for every bit that is
            // set in this field.
            // 
            // Example:
            // docFf = 1011
            // clrFf = 1101
            // clrFfValue = 0010;
            // newValue = 1011 & 0010 which is 0010
            int clrFfValue = clrFf;
            clrFfValue ^= 0xFFFFFFFF;
            fieldFlags = fieldFlags & clrFfValue;
            setFieldFlags(fieldFlags);
        }
    }
}
Also used : COSStream(com.tom_roush.pdfbox.cos.COSStream) COSName(com.tom_roush.pdfbox.cos.COSName) COSArray(com.tom_roush.pdfbox.cos.COSArray) COSBase(com.tom_roush.pdfbox.cos.COSBase) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString)

Example 33 with COSName

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

the class PDVisibleSigBuilder method createImageForm.

@Override
public void createImageForm(PDResources imageFormResources, PDResources innerFormResource, PDStream imageFormStream, PDRectangle bbox, AffineTransform at, PDImageXObject img) throws IOException {
    PDFormXObject imageForm = new PDFormXObject(imageFormStream);
    imageForm.setBBox(bbox);
    imageForm.setMatrix(at);
    imageForm.setResources(imageFormResources);
    imageForm.setFormType(1);
    imageFormResources.getCOSObject().setDirect(true);
    COSName imageFormName = COSName.getPDFName("n2");
    innerFormResource.put(imageFormName, imageForm);
    COSName imageName = imageFormResources.add(img, "img");
    pdfStructure.setImageForm(imageForm);
    pdfStructure.setImageFormName(imageFormName);
    pdfStructure.setImageName(imageName);
    Log.i("PdfBox-Android", "Created image form");
}
Also used : COSName(com.tom_roush.pdfbox.cos.COSName) PDFormXObject(com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)

Example 34 with COSName

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

the class PDPageContentStream method drawXObject.

/**
 * Draw an xobject(form or image) using the given {@link AffineTransform} to position
 * the xobject.
 *
 * @param xobject The xobject to draw.
 * @param transform the transformation matrix
 * @throws IOException If there is an error writing to the stream.
 * @throws IllegalStateException If the method was called within a text block.
 * @deprecated Use {@link #drawImage(PDImageXObject, Matrix) drawImage(PDImageXObject, Matrix)}
 * or {@link #drawForm(PDFormXObject) drawForm(PDFormXObject)} with
 * {@link #transform(Matrix) transform(Matrix)} instead.
 */
@Deprecated
public void drawXObject(PDXObject xobject, AffineTransform transform) throws IOException {
    if (inTextMode) {
        throw new IllegalStateException("Error: drawXObject is not allowed within a text block.");
    }
    String xObjectPrefix;
    if (xobject instanceof PDImageXObject) {
        xObjectPrefix = "Im";
    } else {
        xObjectPrefix = "Form";
    }
    COSName objMapping = resources.add(xobject, xObjectPrefix);
    saveGraphicsState();
    transform(new Matrix(transform));
    writeOperand(objMapping);
    writeOperator(OperatorName.DRAW_OBJECT);
    restoreGraphicsState();
}
Also used : PDImageXObject(com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject) Matrix(com.tom_roush.pdfbox.util.Matrix) COSName(com.tom_roush.pdfbox.cos.COSName)

Example 35 with COSName

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

the class COSDictionaryMap method convertBasicTypesToMap.

/**
 * This will take a COS dictionary and convert it into COSDictionaryMap.  All cos
 * objects will be converted to their primitive form.
 *
 * @param map The COS mappings.
 * @return A standard java map.
 * @throws IOException If there is an error during the conversion.
 */
public static COSDictionaryMap<String, Object> convertBasicTypesToMap(COSDictionary map) throws IOException {
    COSDictionaryMap<String, Object> retval = null;
    if (map != null) {
        Map<String, Object> actualMap = new HashMap<String, Object>();
        for (COSName key : map.keySet()) {
            COSBase cosObj = map.getDictionaryObject(key);
            Object actualObject = null;
            if (cosObj instanceof COSString) {
                actualObject = ((COSString) cosObj).getString();
            } else if (cosObj instanceof COSInteger) {
                actualObject = ((COSInteger) cosObj).intValue();
            } else if (cosObj instanceof COSName) {
                actualObject = ((COSName) cosObj).getName();
            } else if (cosObj instanceof COSFloat) {
                actualObject = ((COSFloat) cosObj).floatValue();
            } else if (cosObj instanceof COSBoolean) {
                actualObject = ((COSBoolean) cosObj).getValue() ? Boolean.TRUE : Boolean.FALSE;
            } else {
                throw new IOException("Error:unknown type of object to convert:" + cosObj);
            }
            actualMap.put(key.getName(), actualObject);
        }
        retval = new COSDictionaryMap<String, Object>(actualMap, map);
    }
    return retval;
}
Also used : COSInteger(com.tom_roush.pdfbox.cos.COSInteger) COSName(com.tom_roush.pdfbox.cos.COSName) HashMap(java.util.HashMap) COSBase(com.tom_roush.pdfbox.cos.COSBase) COSString(com.tom_roush.pdfbox.cos.COSString) IOException(java.io.IOException) COSString(com.tom_roush.pdfbox.cos.COSString) COSBoolean(com.tom_roush.pdfbox.cos.COSBoolean) COSFloat(com.tom_roush.pdfbox.cos.COSFloat)

Aggregations

COSName (com.tom_roush.pdfbox.cos.COSName)83 COSBase (com.tom_roush.pdfbox.cos.COSBase)50 COSArray (com.tom_roush.pdfbox.cos.COSArray)27 IOException (java.io.IOException)24 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)23 COSObject (com.tom_roush.pdfbox.cos.COSObject)11 COSString (com.tom_roush.pdfbox.cos.COSString)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)9 COSStream (com.tom_roush.pdfbox.cos.COSStream)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)7 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)5 COSInteger (com.tom_roush.pdfbox.cos.COSInteger)5 COSNumber (com.tom_roush.pdfbox.cos.COSNumber)5 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)5 PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)4 PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)4 OutputStream (java.io.OutputStream)4 Operator (com.tom_roush.pdfbox.contentstream.operator.Operator)3