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


Java PdfContentByte.createTemplate方法代码示例

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


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

示例1: print

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void print(String plot_pdf) {
	try {
		float width = jframe.getSize().width,
				height = jframe.getSize().height;
		Document document = new Document(new Rectangle(width, height));
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
		document.open();
		PdfContentByte canvas = writer.getDirectContent();
		PdfTemplate template = canvas.createTemplate(width, height);
		Graphics2D g2d = new PdfGraphics2D(template, width, height);
		jframe.paint(g2d);
		g2d.dispose();
		canvas.addTemplate(template, 0, 0);
		document.close();
	} catch (FileNotFoundException | DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:c-zhou,项目名称:polyGembler,代码行数:20,代码来源:JfreeChart.java

示例2: writeChartToPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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

示例3: createRoundRectangle

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void createRoundRectangle(PdfContentByte cb, Block block ){
	PdfDocument request =  getPdfDocument(block);
	float[] positions = getBoundsInPs(block);
	float[] mmPositions = getBoundsInMMIncludeCutmark(block);
	PdfTemplate tp = cb.createTemplate(positions[2],positions[3]);

	tp.roundRectangle(
			0, 
			0, 
			positions[2], 
			positions[3], 
			SizeFactory.millimetersToPostscriptPoints( block.getRadius() )
	);
	
	
	
	
	// because pdf i calculated from bottom up
	cb.addTemplate(
			tp, 
			positions[0], 
			SizeFactory.millimetersToPostscriptPoints( request.getSize()[1] - ( mmPositions[1] + mmPositions[3]))
	);

}
 
开发者ID:Billes,项目名称:pdf-renderer,代码行数:26,代码来源:BlockFactory.java

示例4: createMultipagePDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Create the multipage PDF report from the internal list of JPanels.
 * @throws DocumentException 
 */
public void createMultipagePDF() throws DocumentException {
	// Document defaults to A4, so specify the current dimensions
	Document doc= new Document(new Rectangle(pageWidth, pageHeight));
	PdfWriter writer= PdfWriter.getInstance(doc, os);
	doc.open();
	PdfContentByte cb= writer.getDirectContent();
	
	// Iterate over tabs
	for (int i= 0; i != tabs.getTabCount(); ++i) {
		JPanel jp= (JPanel) tabs.getComponent(i);
		// Iterate over pages
		for (int currentPage= 0; currentPage < getNumPages(jp); ++currentPage) {
			doc.newPage(); // not needed for page 1, needed for >1

			PdfTemplate template= cb.createTemplate(pageWidth, pageHeight);
			Graphics2D g2d= new PdfGraphics2D(template, pageWidth, pageHeight * (currentPage + 1));
			jp.printAll(g2d);
			g2d.dispose();

			cb.addTemplate(template, 0, 0);
		}
	}
	
	doc.close();
}
 
开发者ID:BaderLab,项目名称:pharmacogenomics,代码行数:30,代码来源:PGXPDFExporter.java

示例5: writeToFile

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public static void writeToFile(File f, Component m) throws Exception {
    Graphics2D g2;
    
    Document document = new Document(new Rectangle(
            m.getBounds().x,
            m.getBounds().y,
            m.getBounds().width,
            m.getBounds().height
            ));
    PdfWriter writer;
    writer = PdfWriter.getInstance(document, new FileOutputStream(f));

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

    g2 = tp.createGraphicsShapes(m.getSize().width, m.getSize().height);

    m.paint(g2);
    g2.dispose();
    cb.addTemplate(tp, 0, 0);
    document.close();
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:24,代码来源:PDFExporter.java

示例6: renderGral

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private List<Element> renderGral(String raw) throws BadElementException, IOException {
    ChartDescriptor descriptor = new ChartDescriptorParser().parse(raw);

    PdfContentByte cb = writer.get().getDirectContent();
    float width = (float) descriptor.getWidth();
    float height = (float) descriptor.getHeight();

    PdfTemplate template = cb.createTemplate(width, height);
    Graphics2D g2 = new PdfGraphics2D(template, width, height);

    GralRenderer renderer = new GralRenderer();
    renderer.render(g2, descriptor);

    ArrayList<Element> elements = new ArrayList<Element>(1);
    elements.add(new ImgTemplate(template));
    return elements;
}
 
开发者ID:Arnauld,项目名称:cucumber-contrib,代码行数:18,代码来源:GralProcessor.java

示例7: exportChartAsPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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

示例8: exportChartAsPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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

示例9: createEvent

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public PdfPCellEvent createEvent(final Block block ){
	return new PdfPCellEvent(){
		public void cellLayout(PdfPCell cell, Rectangle rect,PdfContentByte[] canvas) {
			
			float radiusInPs = SizeFactory.millimetersToPostscriptPoints( block.getRadius() );
			PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
			PdfTemplate template = cb.createTemplate( rect.getWidth() , rect.getHeight());
			template.roundRectangle(0, 0,  rect.getWidth() ,rect.getHeight() , radiusInPs);
			template.clip();
			template.newPath();
			
			if( block.getBaseColor() != null ){
				template.setColorFill(block.getBaseColor());
			}
			
			Border border = block.getBorder();

			if( border != null ){
				template.setLineWidth( SizeFactory.millimetersToPostscriptPoints( border.getThickness()) );
				template.setColorStroke( border.getBaseColor());
			}
			
			template.roundRectangle(0, 0,  rect.getWidth() ,rect.getHeight() ,radiusInPs);
				
			if( block.getBaseColor() != null || border != null ){
				if( block.getBaseColor() != null &&  border != null ){
					template.fillStroke();
				}else if( block.getBaseColor() != null ){
					template.fill();
				}else{
					
					template.stroke();
				}
			}
			cb.addTemplate( template, rect.getLeft(), rect.getBottom());
		}
	};
}
 
开发者ID:Billes,项目名称:pdf-renderer,代码行数:39,代码来源:CellBlockEvent.java

示例10: exportToPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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

示例11: saveAsPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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

示例12: saveRAWAsPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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

示例13: writeChartToPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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

示例14: save

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public static final void save(File file, Component c, int width, int height) {
	if (file == null) {
		logger.log(Level.WARNING, "no file selected");
		return;
	}
	if (c == null) {
		logger.log(Level.WARNING, "no component provided");
		return;
	}
	try {
		Document document = new Document(new Rectangle(width, height));
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file.getAbsolutePath()));
		document.addAuthor("UJMP v" + UJMP.UJMPVERSION);
		document.open();
		PdfContentByte cb = writer.getDirectContent();
		PdfTemplate tp = cb.createTemplate(width, height);
		Graphics2D g2 = new PdfGraphics2D(cb, width, height, new DefaultFontMapper());
		if (c instanceof CanRenderGraph) {
			((CanRenderGraph) c).renderGraph(g2);
		} else {
			c.paint(g2);
		}
		g2.dispose();
		cb.addTemplate(tp, 0, 0);
		document.close();
		writer.close();
	} catch (Exception e) {
		logger.log(Level.WARNING, "could not save PDF file", e);
	}
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:31,代码来源:ExportPDF.java

示例15: writeChartToPDF

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的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


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