List of usage examples for com.itextpdf.text.pdf PdfTemplate setGState
public void setGState(final PdfGState gstate)
From source file:com.vectorprint.report.jfree.ItextChartHelper.java
License:Open Source License
/** * * @param chart the chart tp plot//from w ww. j av a2 s.c o m * @param contentByte the canvas to plot to * @param width the width of the chart will be fit to * @param height the height of the chart will be fit to * @return * @throws BadElementException */ public static Image getChartImage(JFreeChart chart, PdfContentByte contentByte, float width, float height, float opacity) throws BadElementException { // create PdfTemplate from PdfContentByte PdfTemplate template = contentByte.createTemplate(width, height); template.saveState(); PdfGState pgs = new PdfGState(); pgs.setFillOpacity(opacity); pgs.setStrokeOpacity(opacity); template.setGState(pgs); // create Graphics2D from PdfTemplate Graphics2D g2 = new PdfGraphics2D(template, width, height); // setup the drawing area Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height); // pass the Graphics2D and drawing area to JFreeChart chart.draw(g2, r2D); g2.dispose(); // always dispose this template.restoreState(); // create Image from PdfTemplate return Image.getInstance(template); }