当前位置: 首页>>代码示例>>Java>>正文


Java PdfTemplate.createGraphics方法代码示例

本文整理汇总了Java中com.itextpdf.text.pdf.PdfTemplate.createGraphics方法的典型用法代码示例。如果您正苦于以下问题:Java PdfTemplate.createGraphics方法的具体用法?Java PdfTemplate.createGraphics怎么用?Java PdfTemplate.createGraphics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.itextpdf.text.pdf.PdfTemplate的用法示例。


在下文中一共展示了PdfTemplate.createGraphics方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeChartToPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Save the chart as pdf.
 *
 * @param chart
 *            chart that should be saved
 * @param fileName
 *            file name under which chart should be saved
 */
public static void writeChartToPDF(final JFreeChart chart,
		final String fileName) {
	PdfWriter writer = null;

	com.itextpdf.text.Document document = new com.itextpdf.text.Document(
			PageSize.A4);
	final int width = (int) PageSize.A4.getWidth();
	final int height = (int) PageSize.A4.getHeight();

	try {
		writer = PdfWriter.getInstance(document, new FileOutputStream(
				fileName + ".pdf"));
		document.open();
		PdfContentByte contentByte = writer.getDirectContent();
		PdfTemplate template = contentByte.createTemplate(width, height);
		Graphics2D graphics2d = template.createGraphics(width, height,
				new DefaultFontMapper());
		Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
				height);

		chart.draw(graphics2d, rectangle2d);

		graphics2d.dispose();
		contentByte.addTemplate(template, 0, 0);

	} catch (Exception e) {
		e.printStackTrace();
	}
	document.close();
}
 
开发者ID:adamIqbal,项目名称:Health,代码行数:39,代码来源:Histogram.java

示例2: exportChartAsPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Exports the specified JFreeChart to a PDF file using
 * <a href="http://itextpdf.com" target="_blank">iText</a>, bundled with
 * Fiji. The destination file is specified by the user in a save dialog
 * prompt. An error message is displayed if the file could not be saved.
 * Does nothing if {@code chart} is {@code null}.
 *
 * @param chart
 *            the <a href="http://javadoc.imagej.net/JFreeChart/" target=
 *            "_blank">JFreeChart </a> to export.
 * @param bounds
 *            the Rectangle delimiting the boundaries within which the chart
 *            should be drawn.
 * @see #exportChartAsPDF(JFreeChart, Rectangle)
 * @see #exportChartAsSVG(JFreeChart, Rectangle)
 * @see #exportChartAsSVG(JFreeChart, Rectangle, File)
 */
public static void exportChartAsPDF(final JFreeChart chart, final Rectangle bounds, final File f)
		throws FileNotFoundException, DocumentException {

	final int margin = 0; // page margins

	// Initialize writer
	final Document document = new Document(new com.itextpdf.text.Rectangle(bounds.width, bounds.height), margin,
			margin, margin, margin);
	final PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f));

	document.open();
	final PdfContentByte cb = writer.getDirectContent();
	final PdfTemplate tp = cb.createTemplate(bounds.width, bounds.height);

	// Draw the chart. Release resources upon completion
	final Graphics2D g2 = tp.createGraphics(bounds.width, bounds.height, new DefaultFontMapper());
	chart.draw(g2, bounds);
	g2.dispose();

	// Write to file
	cb.addTemplate(tp, 0, 0);

	document.close();
}
 
开发者ID:tferr,项目名称:Scripts,代码行数:42,代码来源:PlotUtils.java

示例3: exportChartAsPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
public static void exportChartAsPDF(
        JFreeChart chart,
        Rectangle bounds,
        File file) throws IOException, DocumentException {

    System.out.println(file.getPath());

    PdfWriter writer = null;
    com.itextpdf.text.Document document = new com.itextpdf.text.Document();

    document.addCreator("CanReg5");
    document.addCreationDate();

    writer = PdfWriter.getInstance(document, new FileOutputStream(
            file));
    document.open();
    PdfContentByte contentByte = writer.getDirectContent();
    PdfTemplate template = contentByte.createTemplate(bounds.width, bounds.height);
    Graphics2D graphics2d = template.createGraphics(bounds.width, bounds.height,
            new DefaultFontMapper());
    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, bounds.width,
            bounds.height);

    chart.draw(graphics2d, rectangle2d);

    graphics2d.dispose();
    contentByte.addTemplate(template, 0, 0);

    document.close();
}
 
开发者ID:IARC-CSU,项目名称:CanReg5,代码行数:31,代码来源:Tools.java

示例4: exportToPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Exports the 3d graph as a pdf
 * 
 * @param file The pdf file to which the data should be written
 * @param panel The chart panel that has to be exported
 */
public static void exportToPDF(File file, Chart3DPanel panel){
	
	PdfWriter out = null;
	Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());
	
	int width = 800, height = 500;
	
	try{
		
		out = PdfWriter.getInstance(document, new FileOutputStream(file));
		document.open();
		PdfContentByte contentByte = out.getDirectContent();
		PdfTemplate template = contentByte.createTemplate(width, height);
		@SuppressWarnings("deprecation")
		Graphics2D graphics2d = template.createGraphics(width, height,new DefaultFontMapper());
		Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,height);

		panel.getChart().draw(graphics2d, rectangle2d);

		graphics2d.dispose();
		contentByte.addTemplate(template, 0, 0);
		
		
	} catch(Exception e){
		// in case any error occurs tell the user what the error is (sometimes useful if there is a problem of writing rights)
		JOptionPane.showMessageDialog(GUIPrism.getGUI(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
		e.printStackTrace();
		return;
	}
	
	document.close();
}
 
开发者ID:musaeed,项目名称:Prism-gsoc16,代码行数:39,代码来源:Graph3D.java

示例5: saveAsPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Stores the logo in PDF format
 * @param width
 * @param height
 * @param fileName 
 */
public void saveAsPDF(int width, int height, String fileName) 
{
	if (chart == null)
	{
		makeSequenceLogo();
	}
	
    PdfWriter writer = null;
 
    Rectangle pagesize = new Rectangle(width, height);
    Document document = new Document(pagesize);
 
    try 
    {
        writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(width, height);
        Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);
 
        chart.draw(graphics2d, rectangle2d);
         
        graphics2d.dispose();
        contentByte.addTemplate(template, 0, 0);
 
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    document.close();
}
 
开发者ID:drivenbyentropy,项目名称:aptasuite,代码行数:40,代码来源:Logo.java

示例6: saveRAWAsPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Stores the logo in PDF format
 * @param width
 * @param height
 * @param fileName 
 */
public void saveRAWAsPDF(int width, int height, String fileName) 
{
	
	ChartPanel logo = getRawLogoPanel();
	
    PdfWriter writer = null;
 
    Rectangle pagesize = new Rectangle(width, height);
    Document document = new Document(pagesize);
 
    try 
    {
        writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(width, height);
        Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);
 
        logo.getChart().draw(graphics2d, rectangle2d);
         
        graphics2d.dispose();
        contentByte.addTemplate(template, 0, 0);
 
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    document.close();
}
 
开发者ID:drivenbyentropy,项目名称:aptasuite,代码行数:38,代码来源:Logo.java

示例7: writeChartToPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Save chart as a pdf file.
 *
 * @param chart
 *            chart that should be saved
 * @param fileName
 *            file name under which the file should be saved
 */
public static void writeChartToPDF(final JFreeChart chart,
		final String fileName) {
	PdfWriter writer = null;

	com.itextpdf.text.Document document = new com.itextpdf.text.Document(
			PageSize.A4);
	final int width = (int) PageSize.A4.getWidth();
	final int height = (int) PageSize.A4.getHeight();

	try {
		writer = PdfWriter.getInstance(document, new FileOutputStream(
				fileName + ".pdf"));
		document.open();
		PdfContentByte contentByte = writer.getDirectContent();
		PdfTemplate template = contentByte.createTemplate(width, height);
		Graphics2D graphics2d = template.createGraphics(width, height,
				new DefaultFontMapper());
		Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
				height);

		chart.draw(graphics2d, rectangle2d);

		graphics2d.dispose();
		contentByte.addTemplate(template, 0, 0);

	} catch (Exception e) {
		e.printStackTrace();
	}
	document.close();
}
 
开发者ID:adamIqbal,项目名称:Health,代码行数:39,代码来源:BoxPlot.java

示例8: writeChartToPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * This method saves a chart as a PDF with given dimensions
 * 
 * @param chart
 * @param width
 * @param height
 * @param fileName is a full path
 */
public static void writeChartToPDF(JFreeChart chart, int width, int height, File fileName)
    throws Exception {
  PdfWriter writer = null;

  Document document = new Document(new Rectangle(width, height));

  try {
    writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
    document.open();
    PdfContentByte contentByte = writer.getDirectContent();
    PdfTemplate template = contentByte.createTemplate(width, height);
    Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);

    chart.draw(graphics2d, rectangle2d);

    graphics2d.dispose();
    contentByte.addTemplate(template, 0, 0);

  } catch (Exception e) {
    e.printStackTrace();
    throw e;
  } finally {
    document.close();
  }
}
 
开发者ID:mzmine,项目名称:mzmine2,代码行数:35,代码来源:ChartExportUtil.java

示例9: writeChartToPDFClipped

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
public static void writeChartToPDFClipped(JFreeChart chart, int width, int height, String fileName) {
    PdfWriter writer = null;

    Document document = new Document();

    try {
        writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();
        document.setPageSize(new com.itextpdf.text.Rectangle(width, height));
        if (document.isOpen()) {
            document.newPage();
        } else {
            document.open();
        }

        PdfContentByte contentByte = writer.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(width, height);
        Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(graphics2d, rectangle2d);

        graphics2d.dispose();
        contentByte.addTemplate(template, 0, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    document.close();
}
 
开发者ID:lkrcmar,项目名称:MWEs,代码行数:29,代码来源:PdfGraphPrinter.java

示例10: createPdfViaTemplate

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Creates a pdf showing the given {@link PlotterTemplate} via {@link PdfTemplate} usage.
 * @param template
 * @param document
 * @param cb
 * @throws DocumentException
 */
private void createPdfViaTemplate(PlotterTemplate template, Document document,PdfContentByte cb) throws DocumentException {
	PdfTemplate tp = cb.createTemplate(500, PageSize.A4.getHeight()/2);
	Graphics2D g2 = tp.createGraphics(500, PageSize.A4.getHeight()/2);
	AffineTransform at = new AffineTransform();
	double factor = 500d / template.getPlotEngine().getChartPanel().getWidth();
	at.scale(factor, factor);
	g2.transform(at);
	template.getPlotEngine().getChartPanel().print(g2);
	g2.dispose();
	document.add(new Paragraph(componentName));
	document.add(Image.getInstance(tp));
}
 
开发者ID:rapidminer,项目名称:rapidminer-5,代码行数:20,代码来源:ExportPdfAction.java

示例11: writeAsPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Save chart as PDF file. Requires iText library.
 * 
 * @param chart JFreeChart to save.
 * @param fileName Name of file to save chart in.
 * @param width Width of chart graphic.
 * @param height Height of chart graphic.
 * @throws Exception if failed.
 * @see <a href="http://www.lowagie.com/iText">iText</a>
 */
@SuppressWarnings("deprecation")
public static void writeAsPDF(File fileToSave, int width, int height) throws Exception {
	
	if (chart != null)
	{
		BufferedOutputStream out = null;
		try
		{
			out = new BufferedOutputStream(new FileOutputStream(fileToSave.getAbsolutePath()));
			
			// convert chart to PDF with iText:
			Rectangle pagesize = new Rectangle(width, height);
			Document document = new Document(pagesize, 50, 50, 50, 50);
			try
			{
				PdfWriter writer = PdfWriter.getInstance(document, out);
				document.addAuthor("JFreeChart");
				document.open();
				
				PdfContentByte cb = writer.getDirectContent();
				PdfTemplate tp = cb.createTemplate(width, height);
				Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
				
				Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
				chart.draw(g2, r2D, null);
				g2.dispose();
				cb.addTemplate(tp, 0, 0);
			}
			finally
			{
				document.close();
			}
		}
		finally
		{
			if (out != null)
				out.close();
		}
	}
}
 
开发者ID:petebrew,项目名称:fhaes,代码行数:51,代码来源:SSIZCurveChart.java

示例12: exportToPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
/**
 * Exports the given chart to a pdf format file
 * @param file the file that has to be saved in pdf format
 * @param chart the chart that needs to be exported into pdf
 */

public static void exportToPDF(File file, JFreeChart chart){
	
	PdfWriter out = null;
	com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());
	
	int width = 800, height = 500;
	
	try{
		
		out = PdfWriter.getInstance(document, new FileOutputStream(file));
		document.open();
		PdfContentByte contentByte = out.getDirectContent();
		PdfTemplate template = contentByte.createTemplate(width, height);
		@SuppressWarnings("deprecation")
		Graphics2D graphics2d = template.createGraphics(width, height,new DefaultFontMapper());
		Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,height);

		chart.draw(graphics2d, rectangle2d);

		graphics2d.dispose();
		contentByte.addTemplate(template, 0, 0);
		
	} catch(Exception e){
		
		JOptionPane.showMessageDialog(GUIPrism.getGUI(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
		e.printStackTrace();
		return;
	}
	
	document.close();
	
}
 
开发者ID:musaeed,项目名称:Prism-gsoc16,代码行数:39,代码来源:Graph.java

示例13: writeChartsToPDF

import com.itextpdf.text.pdf.PdfTemplate; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static void writeChartsToPDF(List<JFreeChart> charts, int width, int height, OutputStream outputStream, String hostname, Date date) {
	PdfWriter writer = null;

	Document document = new Document();

	
	try {
		
		writer = PdfWriter.getInstance(document, outputStream);
		writer.setPageEmpty(false);
		
		
		
		document.open();
		document.setPageSize(PageSize.A4);
		document.add(new Paragraph("Aggregates Report generated by " + hostname + " on " + date.toString()));
		document.newPage();
		writer.newPage();
		
		PdfContentByte contentByte = writer.getDirectContent();
		
		PdfTemplate template;
		Graphics2D graphics2d;
		
		
		int position = 0;
		Rectangle2D rectangle2d;
		
		
		for (JFreeChart chart : charts){
			LOG.debug("Writing chart to PDF");
			if (writer.getVerticalPosition(true)-height+(height*position) < 0){
				position = 0;
				document.newPage();
				writer.newPage();					
				
			}
			template = contentByte.createTemplate(width, height);
			graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
			rectangle2d = new Rectangle2D.Double(0, 0, width, height);
			chart.draw(graphics2d, rectangle2d);
			graphics2d.dispose();

			
			contentByte.addTemplate(template, 38, writer.getVerticalPosition(true)-height+(height*position));
			position--;
			
			

		}

	} catch (Exception e) {
		e.printStackTrace();
	}
	document.close();
}
 
开发者ID:cvtienhoven,项目名称:graylog-plugin-aggregates,代码行数:58,代码来源:ReportFactory.java


注:本文中的com.itextpdf.text.pdf.PdfTemplate.createGraphics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。