Java 类com.lowagie.text.pdf.PdfGState 实例源码

项目:reportJ    文件:PdfWrappedStamper.java   
public static void init() {
    instance = new PdfWrappedStamper();
    try {
        //png image  
        imageEnabled = GlobalConfig.getInstance().getStamperImageEnabled();
        if (imageEnabled){
            image = Image.getInstance(getResourcePath()+GlobalConfig.getInstance().getStamperImagePath());
            image.setAlignment(Image.LEFT | Image.TEXTWRAP);  
            image.setBorderWidth(10); 
            image.scaleToFit(GlobalConfig.getInstance().getStamperImageWidth(), GlobalConfig.getInstance().getStamperImageHeight());//size
            gsFixed = new PdfGState();
            gsDynamic = new PdfGState();
            gsFixed.setFillOpacity(GlobalConfig.getInstance().getStamperFixedImageTransparent());
            gsDynamic.setFillOpacity(GlobalConfig.getInstance().getStamperDynamicImageTransparent());
        }
    } catch (Exception e) {
        log.error(e.getMessage(),e);
    }
}
项目:geomajas-project-server    文件:PdfContext.java   
/**
 * Draws the specified image with the first rectangle's bounds, clipping with the second one.
 *
 * @param img image
 * @param rect rectangle
 * @param clipRect clipping bounds
 * @param opacity opacity of the image (1 = opaque, 0= transparent)
 */
public void drawImage(Image img, Rectangle rect, Rectangle clipRect, float opacity) {
    try {
        template.saveState();
        // opacity
        PdfGState state = new PdfGState();
        state.setFillOpacity(opacity);
        state.setBlendMode(PdfGState.BM_NORMAL);
        template.setGState(state);
        // clipping code
        if (clipRect != null) {
            template.rectangle(clipRect.getLeft() + origX, clipRect.getBottom() + origY, clipRect.getWidth(),
                    clipRect.getHeight());
            template.clip();
            template.newPath();
        }
        template.addImage(img, rect.getWidth(), 0, 0, rect.getHeight(), origX + rect.getLeft(), origY
                + rect.getBottom());
    } catch (DocumentException e) {
        log.warn("could not draw image", e);
    } finally {
        template.restoreState();
    }
}
项目:itext2    文件:GroupsTest.java   
/**
 * Prints 3 circles in different colors that intersect with eachother.
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
public static void pictureCircles(float x, float y, PdfContentByte cb) throws Exception {
    PdfGState gs = new PdfGState();
    gs.setBlendMode(PdfGState.BM_SOFTLIGHT);
    gs.setFillOpacity(0.7f);
    cb.setGState(gs);
    cb.setColorFill(Color.gray);
    cb.circle(x + 70, y + 70, 50);
    cb.fill();
    cb.circle(x + 100, y + 130, 50);
    cb.fill();
    cb.circle(x + 130, y + 70, 50);
    cb.fill();
}
项目:PDFTestForAndroid    文件:Groups.java   
/**
 * Prints 3 circles in different colors that intersect with eachother.
 * 
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
public static void pictureCircles(float x, float y, PdfContentByte cb) throws Exception {
    PdfGState gs = new PdfGState();
    gs.setBlendMode(PdfGState.BM_SOFTLIGHT);
    gs.setFillOpacity(0.7f);
    cb.setGState(gs);
    cb.setColorFill(Color.gray);
    cb.circle(x + 70, y + 70, 50);
    cb.fill();
    cb.circle(x + 100, y + 130, 50);
    cb.fill();
    cb.circle(x + 130, y + 70, 50);
    cb.fill();
}
项目:geomajas-project-server    文件:PdfContext.java   
private void setStroke(Color color, float linewidth, float[] dashArray) {
    // Color and transparency
    PdfGState state = new PdfGState();
    state.setStrokeOpacity(color.getAlpha());
    state.setBlendMode(PdfGState.BM_NORMAL);
    template.setGState(state);
    template.setColorStroke(color);
    // linewidth
    template.setLineWidth(linewidth);
    if (dashArray != null) {
        template.setLineDash(dashArray, 0f);
    }
}
项目:geomajas-project-server    文件:PdfContext.java   
private void setFill(Color color) {
    // Color and transparency
    PdfGState state = new PdfGState();
    state.setFillOpacity(color.getAlpha() / 255f);
    state.setBlendMode(PdfGState.BM_NORMAL);
    template.setGState(state);
    template.setColorFill(color);
}
项目:itext2    文件:GStateTest.java   
/**
 * Changing the Graphics State with PdfGState.
 * 
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter writer = PdfWriter.getInstance(document,
                PdfTestBase.getOutputStream( "gstate.pdf"));

        // step 3: we open the document
        document.open();

        // step 4: we grab the ContentByte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();

           PdfGState gs = new PdfGState();
           gs.setFillOpacity(0.5f);
           cb.setGState(gs);
        cb.setColorFill(Color.red);
        cb.circle(260.0f, 500.0f, 250.0f);
        cb.fill();
        cb.circle(260.0f, 500.0f, 200.0f);
        cb.fill();
        cb.circle(260.0f, 500.0f, 150.0f);
        cb.fill();
        gs.setFillOpacity(0.2f);
        cb.setGState(gs);
        cb.setColorFill(Color.blue);
        cb.circle(260.0f, 500.0f, 100.0f);
        cb.fill();
        cb.circle(260.0f, 500.0f, 50.0f);
        cb.fill();

        cb.sanityCheck();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}
项目:PDFTestForAndroid    文件:GState.java   
/**
 * Changing the Graphics State with PdfGState.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
    System.out.println("Changing the Graphics State with PdfGState");

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a file
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "gstate.pdf"));

        // step 3: we open the document
        document.open();

        // step 4: we grab the ContentByte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();

        PdfGState gs = new PdfGState();
        gs.setFillOpacity(0.5f);
        cb.setGState(gs);
        cb.setColorFill(Color.red);
        cb.circle(260.0f, 500.0f, 250.0f);
        cb.fill();
        cb.circle(260.0f, 500.0f, 200.0f);
        cb.fill();
        cb.circle(260.0f, 500.0f, 150.0f);
        cb.fill();
        gs.setFillOpacity(0.2f);
        cb.setGState(gs);
        cb.setColorFill(Color.blue);
        cb.circle(260.0f, 500.0f, 100.0f);
        cb.fill();
        cb.circle(260.0f, 500.0f, 50.0f);
        cb.fill();

        cb.sanityCheck();
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}