Search in sources :

Example 1 with PDTransparencyGroup

use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project PdfBox-Android by TomRoush.

the class PageDrawer method showTransparencyGroup.

@Override
public void showTransparencyGroup(PDTransparencyGroup form) throws IOException {
    if (!isContentRendered()) {
        return;
    }
    TransparencyGroup group = new TransparencyGroup(form, false, getGraphicsState().getCurrentTransformationMatrix(), null);
    // Bitmap image = group.getImage();
    // if (image == null)
    // {
    // image is empty, don't bother
    // return;
    // }
    // graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
    setClip();
    // both the DPI xform and the CTM were already applied to the group, so all we do
    // here is draw it directly onto the Graphics2D device at the appropriate position
    // PDRectangle bbox = group.getBBox();
    // AffineTransform savedTransform = graphics.getTransform();
    Matrix m = new Matrix(xform);
    float xScale = Math.abs(m.getScalingFactorX());
    float yScale = Math.abs(m.getScalingFactorY());
    AffineTransform transform = new AffineTransform(xform);
    transform.scale(1.0 / xScale, 1.0 / yScale);
    if (flipTG) {
    // graphics.translate(0, image.getHeight());
    // graphics.scale(1, -1);
    } else {
    // graphics.translate(x * xScale, y * yScale);
    }
    PDSoftMask softMask = getGraphicsState().getSoftMask();
    if (softMask != null) {
        // graphics.setPaint(awtPaint);
        if (isContentRendered()) {
        // graphics.fill(
        // new Rectangle2D.Float(0, 0, bbox.getWidth() * xScale, bbox.getHeight() * yScale));
        }
    } else {
        if (isContentRendered()) {
        // try
        // {
        // graphics.drawImage(image, null, null);
        // }
        // catch (InternalError ie)
        // {
        // Log.e("PdfBox-Android", "Exception drawing image, see JDK-6689349, " +
        // "try rendering into a BufferedImage instead", ie);
        // }
        }
    }
// graphics.setTransform(savedTransform);
}
Also used : PDSoftMask(com.tom_roush.pdfbox.pdmodel.graphics.state.PDSoftMask) PDTransparencyGroup(com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup) Matrix(com.tom_roush.pdfbox.util.Matrix) AffineTransform(com.tom_roush.harmony.awt.geom.AffineTransform)

Example 2 with PDTransparencyGroup

use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project PdfBox-Android by TomRoush.

the class PageDrawer method hasBlendMode.

private boolean hasBlendMode(PDTransparencyGroup group, Set<COSBase> groupsDone) {
    if (groupsDone.contains(group.getCOSObject())) {
        // The group was already processed. Avoid endless recursion.
        return false;
    }
    groupsDone.add(group.getCOSObject());
    PDResources resources = group.getResources();
    if (resources == null) {
        return false;
    }
    for (COSName name : resources.getExtGStateNames()) {
        PDExtendedGraphicsState extGState = resources.getExtGState(name);
        if (extGState == null) {
            continue;
        }
        BlendMode blendMode = extGState.getBlendMode();
        if (blendMode != BlendMode.NORMAL) {
            return true;
        }
    }
    // Recursively process nested transparency groups
    for (COSName name : resources.getXObjectNames()) {
        PDXObject xObject;
        try {
            xObject = resources.getXObject(name);
        } catch (IOException ex) {
            continue;
        }
        if (xObject instanceof PDTransparencyGroup && hasBlendMode((PDTransparencyGroup) xObject, groupsDone)) {
            return true;
        }
    }
    return false;
}
Also used : PDTransparencyGroup(com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup) 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) IOException(java.io.IOException) PDXObject(com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)

Example 3 with PDTransparencyGroup

use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project PdfBox-Android by TomRoush.

the class PDXObject method createXObject.

/**
 * Creates a new XObject instance of the appropriate type for the COS stream.
 *
 * @param base The stream which is wrapped by this XObject.
 * @param resources
 * @return A new XObject instance.
 * @throws java.io.IOException if there is an error creating the XObject.
 */
public static PDXObject createXObject(COSBase base, PDResources resources) throws IOException {
    if (base == null) {
        // TODO throw an exception?
        return null;
    }
    if (!(base instanceof COSStream)) {
        throw new IOException("Unexpected object type: " + base.getClass().getName());
    }
    COSStream stream = (COSStream) base;
    String subtype = stream.getNameAsString(COSName.SUBTYPE);
    if (COSName.IMAGE.getName().equals(subtype)) {
        return new PDImageXObject(new PDStream(stream), resources);
    } else if (COSName.FORM.getName().equals(subtype)) {
        ResourceCache cache = resources != null ? resources.getResourceCache() : null;
        COSDictionary group = (COSDictionary) stream.getDictionaryObject(COSName.GROUP);
        if (group != null && COSName.TRANSPARENCY.equals(group.getCOSName(COSName.S))) {
            return new PDTransparencyGroup(stream, cache);
        }
        return new PDFormXObject(stream, cache);
    } else if (COSName.PS.getName().equals(subtype)) {
        return new PDPostScriptXObject(stream);
    } else {
        throw new IOException("Invalid XObject Subtype: " + subtype);
    }
}
Also used : PDTransparencyGroup(com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup) COSStream(com.tom_roush.pdfbox.cos.COSStream) PDImageXObject(com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) PDFormXObject(com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject) IOException(java.io.IOException) PDStream(com.tom_roush.pdfbox.pdmodel.common.PDStream) ResourceCache(com.tom_roush.pdfbox.pdmodel.ResourceCache)

Example 4 with PDTransparencyGroup

use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project PdfBox-Android by TomRoush.

the class DrawObject method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.isEmpty()) {
        throw new MissingOperandException(operator, arguments);
    }
    COSBase base0 = arguments.get(0);
    if (!(base0 instanceof COSName)) {
        return;
    }
    COSName name = (COSName) base0;
    PDXObject xobject = context.getResources().getXObject(name);
    ((PDFMarkedContentExtractor) context).xobject(xobject);
    if (xobject instanceof PDFormXObject) {
        try {
            context.increaseLevel();
            if (context.getLevel() > 25) {
                Log.e("PdfBox-Android", "recursion is too deep, skipping form XObject");
                return;
            }
            PDFormXObject form = (PDFormXObject) xobject;
            if (form instanceof PDTransparencyGroup) {
                context.showTransparencyGroup((PDTransparencyGroup) form);
            } else {
                context.showForm(form);
            }
        } finally {
            context.decreaseLevel();
        }
    }
}
Also used : PDTransparencyGroup(com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup) COSName(com.tom_roush.pdfbox.cos.COSName) MissingOperandException(com.tom_roush.pdfbox.contentstream.operator.MissingOperandException) PDFMarkedContentExtractor(com.tom_roush.pdfbox.text.PDFMarkedContentExtractor) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDFormXObject(com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject) PDXObject(com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)

Example 5 with PDTransparencyGroup

use of com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup in project PdfBox-Android by TomRoush.

the class DrawObject method process.

@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
    if (arguments.isEmpty()) {
        throw new MissingOperandException(operator, arguments);
    }
    COSBase base0 = arguments.get(0);
    if (!(base0 instanceof COSName)) {
        return;
    }
    COSName name = (COSName) base0;
    if (context.getResources().isImageXObject(name)) {
        // we're done here, don't decode images when doing text extraction
        return;
    }
    PDXObject xobject = context.getResources().getXObject(name);
    if (xobject instanceof PDFormXObject) {
        try {
            context.increaseLevel();
            if (context.getLevel() > 25) {
                Log.e("PdfBox-Android", "recursion is too deep, skipping form XObject");
                return;
            }
            PDFormXObject form = (PDFormXObject) xobject;
            if (form instanceof PDTransparencyGroup) {
                context.showTransparencyGroup((PDTransparencyGroup) form);
            } else {
                context.showForm(form);
            }
        } finally {
            context.decreaseLevel();
        }
    }
}
Also used : PDTransparencyGroup(com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup) COSName(com.tom_roush.pdfbox.cos.COSName) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDFormXObject(com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject) PDXObject(com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)

Aggregations

PDTransparencyGroup (com.tom_roush.pdfbox.pdmodel.graphics.form.PDTransparencyGroup)6 COSName (com.tom_roush.pdfbox.cos.COSName)4 PDXObject (com.tom_roush.pdfbox.pdmodel.graphics.PDXObject)4 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)4 COSBase (com.tom_roush.pdfbox.cos.COSBase)3 MissingOperandException (com.tom_roush.pdfbox.contentstream.operator.MissingOperandException)2 PDImageXObject (com.tom_roush.pdfbox.pdmodel.graphics.image.PDImageXObject)2 IOException (java.io.IOException)2 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSStream (com.tom_roush.pdfbox.cos.COSStream)1 MissingResourceException (com.tom_roush.pdfbox.pdmodel.MissingResourceException)1 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)1 ResourceCache (com.tom_roush.pdfbox.pdmodel.ResourceCache)1 PDStream (com.tom_roush.pdfbox.pdmodel.common.PDStream)1 BlendMode (com.tom_roush.pdfbox.pdmodel.graphics.blend.BlendMode)1 PDExtendedGraphicsState (com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState)1 PDSoftMask (com.tom_roush.pdfbox.pdmodel.graphics.state.PDSoftMask)1 PDFMarkedContentExtractor (com.tom_roush.pdfbox.text.PDFMarkedContentExtractor)1 Matrix (com.tom_roush.pdfbox.util.Matrix)1