Example usage for com.itextpdf.text.pdf PdfGState setBlendMode

List of usage examples for com.itextpdf.text.pdf PdfGState setBlendMode

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfGState setBlendMode.

Prototype

public void setBlendMode(PdfName bm) 

Source Link

Document

The current blend mode to be used in the transparent imaging model.

Usage

From source file:com.vectorprint.report.itext.style.stylers.AdvancedImpl.java

License:Open Source License

/**
 * get a canvas for drawing, prepared according to settings
 *
 * @see #draw(com.itextpdf.text.Rectangle, java.lang.String) 
 * @return/*from  www.jav  a2  s.co  m*/
 */
protected final PdfContentByte getPreparedCanvas(float opacity) {
    needRestore = false;
    PdfContentByte canvas = (tableForeground != null) ? tableForeground
            : (isBg()) ? getWriter().getDirectContentUnder() : getWriter().getDirectContent();
    String layerName = getLayerName();
    BLENDMODE blend = getBlend();
    if (getWriter().getPDFXConformance() == PdfWriter.PDFX1A2001) {
        // check blend, opacity, layers
        if (!PdfGState.BM_NORMAL.equals(blend.getBlend())
                && !PdfGState.BM_COMPATIBLE.equals(blend.getBlend())) {
            throw new VectorPrintRuntimeException("blend not supported in PDF/X-1a: " + blend);
        }
        if (layerName != null) {
            throw new VectorPrintRuntimeException("layers not supported in PDF/X-1a: " + layerName);
        }
        if (opacity < 1) {
            throw new VectorPrintRuntimeException("opacity not supported in PDF/X-1a: " + opacity);
        }
    }
    if (layerName != null) {
        layerManager.startLayerInGroup(layerName, canvas);
    }
    //                pgs.setAlphaIsShape(true);
    if (opacity <= 1) {
        //                        PdfShading shading = PdfShading.simpleAxial(getWriter(), 0, 0, getDocument().right() - getDocument().getPageSize().getWidth() * 0.6f, getDocument().top() - getDocument().getPageSize().getHeight() * 0.6f, Color.green, Color.orange,true,true);
        //                        canvas.paintShading(shading);
        canvas.saveState();
        needRestore = true;
        PdfGState pgs = new PdfGState();
        pgs.setFillOpacity(opacity);
        pgs.setStrokeOpacity(opacity);
        canvas.setGState(pgs);
    }
    if (!BLENDMODE.NORMAL.equals(blend)) {
        if (!needRestore) {
            canvas.saveState();
            needRestore = true;
        }
        PdfGState pgs = new PdfGState();
        pgs.setBlendMode(blend.getBlend());
        canvas.setGState(pgs);
    }
    if (getTransform() != null && !(this instanceof Image)) {
        canvas.transform(new AffineTransform(getTransform()));
    }
    return canvas;
}