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


Java PdfTemplate类代码示例

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


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

示例1: exportVectorGraphics

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException {
	Component component = printableComponent.getExportComponent();
	int width = component.getWidth();
	int height = component.getHeight();
	try (FileOutputStream fs = new FileOutputStream(outputFile)) {
		switch (formatName) {
			case PDF:
				// create pdf document with slightly increased width and height
				// (otherwise the image gets cut off)
				Document document = new Document(new Rectangle(width + 5, height + 5));
				PdfWriter writer = PdfWriter.getInstance(document, fs);
				document.open();
				PdfContentByte cb = writer.getDirectContent();
				PdfTemplate tp = cb.createTemplate(width, height);
				Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
				component.print(g2);
				g2.dispose();
				cb.addTemplate(tp, 0, 0);
				document.close();
				break;
			case SVG:
				exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height)));
				break;
			case EPS:
				exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height)));
				break;
			default:
				// cannot happen
				break;
		}
	} catch (Exception e) {
		throw new ImageExportException(I18N.getMessage(I18N.getUserErrorMessagesBundle(),
				"error.image_export.export_failed"), e);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:36,代码来源:ImageExporter.java

示例2: ImgTemplate

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
/** Creates an Image from a PdfTemplate.
 *
 * @param template the PdfTemplate
 * @throws BadElementException on error
 */
public ImgTemplate(PdfTemplate template) throws BadElementException{
    super((URL)null);
    if (template == null)
        throw new BadElementException("The template can not be null.");
    if (template.getType() == PdfTemplate.TYPE_PATTERN)
        throw new BadElementException("A pattern can not be used as a template to create an image.");
    type = IMGTEMPLATE;
    scaledHeight = template.getHeight();
    setTop(scaledHeight);
    scaledWidth = template.getWidth();
    setRight(scaledWidth);
    setTemplateData(template);
    plainWidth = getWidth();
    plainHeight = getHeight();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:21,代码来源:ImgTemplate.java

示例3: readWMF

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
/** Reads the WMF into a template.
 * @param template the template to read to
 * @throws IOException on error
 * @throws DocumentException on error
 */    
public void readWMF(PdfTemplate template) throws IOException, DocumentException {
    setTemplateData(template);
    template.setWidth(getWidth());
    template.setHeight(getHeight());
    InputStream is = null;
    try {
        if (rawData == null){
            is = url.openStream();
        }
        else{
            is = new java.io.ByteArrayInputStream(rawData);
        }
        MetaDo meta = new MetaDo(is, template);
        meta.readAll();
    }
    finally {
        if (is != null) {
            is.close();
        }
    }
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:27,代码来源:ImgWMF.java

示例4: getInstance

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
/**
 * Gets an instance of a Image from a java.awt.Image.
 * The image is added as a JPEG with a user defined quality.
 *
 * @param cb
 *            the <CODE>PdfContentByte</CODE> object to which the image will be added
 * @param awtImage
 *            the <CODE>java.awt.Image</CODE> to convert
 * @param quality
 *            a float value between 0 and 1
 * @return an object of type <CODE>PdfTemplate</CODE>
 * @throws BadElementException
 *             on error
 * @throws IOException
 */
public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException {
    java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage,
            0, 0, -1, -1, true);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new IOException(
                "java.awt.Image Interrupted waiting for pixels!");
    }
    if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) {
        throw new IOException("java.awt.Image fetch aborted or errored");
    }
    int w = pg.getWidth();
    int h = pg.getHeight();
    PdfTemplate tp = cb.createTemplate(w, h);
    Graphics2D g2d = tp.createGraphics(w, h, true, quality);
    g2d.drawImage(awtImage, 0, 0, null);
    g2d.dispose();
    return getInstance(tp);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:36,代码来源:Image.java

示例5: writeChartAsPDF

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
public static void writeChartAsPDF(OutputStream out,
		JFreeChart chart,
		int width,
		int height,
		FontMapper mapper) throws IOException {
	Rectangle pagesize = new Rectangle(width, height);
	Document document = new Document(pagesize, 50, 50, 50, 50);
	try {
		PdfWriter writer = PdfWriter.getInstance(document, out);
		document.addAuthor("Ross Anderson");
		document.addSubject("Kidney Exchange");
		document.open();
		PdfContentByte cb = writer.getDirectContent();
		PdfTemplate tp = cb.createTemplate(width, height);
		Graphics2D g2 = tp.createGraphics(width, height, mapper);
		Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
		chart.draw(g2, r2D);
		g2.dispose();
		cb.addTemplate(tp, 0, 0);
	}
	catch (DocumentException de) {
		System.err.println(de.getMessage());
	}
	document.close();
}
 
开发者ID:rma350,项目名称:kidneyExchange,代码行数:26,代码来源:JFreeChartUtil.java

示例6: drawCropped

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
@Override
public void drawCropped(IImage image, float xoffset, float yoffset, float x,
		float y, float width, float height) throws DocumentException {
	try {
		
		Image pdfImage =  getImage(image);
		PdfTemplate t = delegate.getPdfWriter().getDirectContent().createTemplate(width, height);
		t.addImage(pdfImage, pdfImage.getWidth(), 0, 0, pdfImage.getHeight(), xoffset, -yoffset+height-pdfImage.getHeight());
		pdfImage = Image.getInstance(t);
		
		pdfImage.setAbsolutePosition(x, y);
		delegate.addImage(pdfImage);
	} catch (Exception e) {
		throw new DocumentException(e);
	}
}
 
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter,代码行数:17,代码来源:Page.java

示例7: setTotalPage

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
public void setTotalPage( ITextArea totalPage )
{
	super.setTotalPage( totalPage );
	isTotalPage = true;
	HashMap<Float, PdfTemplate> map = ( (PDFPageDevice) pageDevice )
			.getTemplateMap( );
	if ( !map.isEmpty( ) )
	{
		float scaleCache = this.scale;
		for ( Entry<Float, PdfTemplate> e : map.entrySet( ) )
		{
			Float s = e.getKey( );
			PdfTemplate template = e.getValue( );
			if ( template != null )
			{
				this.scale = s.floatValue( );
				drawText( totalPage );
			}
		}
		this.scale = scaleCache;
	}
	isTotalPage = false;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:24,代码来源:PDFRender.java

示例8: createTotalPageTemplate

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
private void createTotalPageTemplate( float x, float y, float width,
		float height, float scale )
{
	PdfTemplate template = null;
	if ( pageDevice.hasTemplate( scale ) )
	{
		template = pageDevice.getPDFTemplate( scale );
	}
	else
	{
		template = contentByte.createTemplate( width, height );
		pageDevice.setPDFTemplate( scale, template );
	}
	y = transformY( y, height );
	contentByte.saveState( );
	contentByte.addTemplate( template, x, y );
	contentByte.restoreState( );
}
 
开发者ID:eclipse,项目名称:birt,代码行数:19,代码来源:PDFPage.java

示例9: drawImage

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
protected void drawImage( PdfTemplate image, float imageX, float imageY,
		float height, float width, String helpText )
		throws DocumentException
{
	imageY = transformY( imageY, height );
	contentByte.saveState( );
	contentByte.concatCTM( 1, 0, 0, 1, imageX, imageY );
	float w = image.getWidth( );
	float h = image.getHeight( );
	contentByte.addTemplate( image, width / w, 0f / w, 0f / h, height / h,
			0f, 0f );
	if ( helpText != null )
	{
		showHelpText( imageX, imageY, width, height, helpText );
	}
	contentByte.restoreState( );
}
 
开发者ID:eclipse,项目名称:birt,代码行数:18,代码来源:PDFPage.java

示例10: transSVG

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
protected PdfTemplate transSVG( String svgPath, byte[] svgData, float x,
		float y, float height, float width, String helpText )
		throws IOException, DocumentException
{
	PdfTemplate template = contentByte.createTemplate( width, height );
	Graphics2D g2D = template.createGraphics( width, height );

	PrintTranscoder transcoder = new PrintTranscoder( );
	if ( null != svgData && svgData.length > 0 )
	{
		transcoder.transcode( new TranscoderInput(
				new ByteArrayInputStream( svgData ) ), null );
	}
	else if ( null != svgPath )
	{
		transcoder.transcode( new TranscoderInput( svgPath ), null );
	}
	PageFormat pg = new PageFormat( );
	Paper p = new Paper( );
	p.setSize( width, height );
	p.setImageableArea( 0, 0, width, height );
	pg.setPaper( p );
	transcoder.print( g2D, pg, 0 );
	g2D.dispose( );
	return template;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:27,代码来源:PDFPage.java

示例11: ImgTemplate

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
/** Creats an Image from a PdfTemplate.
 *
 * @param template the PdfTemplate
 * @throws BadElementException on error
 */
public ImgTemplate(PdfTemplate template) throws BadElementException{
    super((URL)null);
    if (template == null)
        throw new BadElementException("The template can not be null.");
    if (template.getType() == PdfTemplate.TYPE_PATTERN)
        throw new BadElementException("A pattern can not be used as a template to create an image.");
    type = IMGTEMPLATE;
    scaledHeight = template.getHeight();
    setTop(scaledHeight);
    scaledWidth = template.getWidth();
    setRight(scaledWidth);
    setTemplateData(template);
    plainWidth = width();
    plainHeight = height();
}
 
开发者ID:MesquiteProject,项目名称:MesquiteArchive,代码行数:21,代码来源:ImgTemplate.java

示例12: convertToPdf

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
/**
  * Converts a JFreeChart to PDF syntax.
  * @param filename	the name of the PDF file
  * @param chart		the JFreeChart
  * @param width		the width of the resulting PDF
  * @param height	the height of the resulting PDF
  */
 public static void convertToPdf(JFreeChart chart, int width, int height, String filename) {
 	// step 1
 	Document document = new Document(new Rectangle(width, height));
 	try {
 		// step 2
 		PdfWriter writer;
writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream(filename));
// step 3
 		document.open();
 		// step 4
 		PdfContentByte cb = writer.getDirectContent();
 		PdfTemplate tp = cb.createTemplate(width, height);
 		Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
 		Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
 		chart.draw(g2d, r2d);
 		g2d.dispose();
 		tp.sanityCheck();
 		cb.addTemplate(tp, 0, 0);
 		cb.sanityCheck();
 	}
 	catch(DocumentException de) {
 		de.printStackTrace();
 	}
 	catch (FileNotFoundException e) {
 		e.printStackTrace();
 	}
 	// step 5
 	document.close();
 }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:37,代码来源:JFreeChartTest.java

示例13: main

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
/**
 * Demonstrates the use of layers.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("optionalcontent.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	// step 3: opening the document
	document.open();
	// step 4: content
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase(
			"Automatic layers, form fields, images, templates and actions",
			new Font(Font.HELVETICA, 18, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
			650, 0);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
	PdfLayerMembership m1 = new PdfLayerMembership(writer);
	m1.addMember(l2);
	m1.addMember(l3);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2 or layer 3");
	Phrase p3 = new Phrase("Text in layer 3");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f);
	cb.endLayer();
	cb.beginLayer(m1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
	cb.endLayer();
	cb.beginLayer(l3);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
	cb.endLayer();
	TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620),
			"field1");
	ff.setBorderColor(Color.blue);
	ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
	ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
	ff.setText("I'm a form field");
	PdfFormField form = ff.getTextField();
	form.setLayer(l4);
	writer.addAnnotation(form);
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
			+ "pngnow.png");
	img.setLayer(l4);
	img.setAbsolutePosition(200, 550);
	cb.addImage(img);
	PdfTemplate tp = cb.createTemplate(100, 20);
	Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12,
			Font.NORMAL, Color.magenta));
	ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0);
	tp.setLayer(l4);
	tp.setBoundingBox(new Rectangle(0, -10, 100, 20));
	cb.addTemplate(tp, 200, 500);
	ArrayList<Object> state = new ArrayList<Object>();
	state.add("toggle");
	state.add(l1);
	state.add(l2);
	state.add(l3);
	state.add(l4);
	PdfAction action = PdfAction.setOCGstate(state, true);
	Chunk ck = new Chunk("Click here to toggle the layers", new Font(
			Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground(
			Color.blue).setAction(action);
	ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck),
			250, 400, 0);
	cb.sanityCheck();

	// step 5: closing the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:82,代码来源:OptionalContentTest.java

示例14: main

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
/**
 * Painting Patterns.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {


	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);

	// 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("pattern.pdf"));

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

	// step 4: we add some content
	PdfContentByte cb = writer.getDirectContent();
	PdfTemplate tp = cb.createTemplate(400, 300);
	PdfPatternPainter pat = cb.createPattern(15, 15, null);
	pat.rectangle(5, 5, 5, 5);
	pat.fill();
	pat.sanityCheck();

	PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV",
			new CMYKColor(0.9f, .2f, .3f, .1f));
	SpotColor spot = new SpotColor(spc_cmyk, 0.25f);
	tp.setPatternFill(pat, spot, .9f);
	tp.rectangle(0, 0, 400, 300);
	tp.fill();
	tp.sanityCheck();

	cb.addTemplate(tp, 50, 50);
	PdfPatternPainter pat2 = cb.createPattern(10, 10, null);
	pat2.setLineWidth(2);
	pat2.moveTo(-5, 0);
	pat2.lineTo(10, 15);
	pat2.stroke();
	pat2.moveTo(0, -5);
	pat2.lineTo(15, 10);
	pat2.stroke();
	cb.setLineWidth(1);
	cb.setColorStroke(Color.black);
	cb.setPatternFill(pat2, Color.red);
	cb.rectangle(100, 400, 30, 210);
	cb.fillStroke();
	cb.setPatternFill(pat2, Color.green);
	cb.rectangle(150, 400, 30, 100);
	cb.fillStroke();
	cb.setPatternFill(pat2, Color.blue);
	cb.rectangle(200, 400, 30, 130);
	cb.fillStroke();
	cb.setPatternFill(pat2, new GrayColor(0.5f));
	cb.rectangle(250, 400, 30, 80);
	cb.fillStroke();
	cb.setPatternFill(pat2, new GrayColor(0.7f));
	cb.rectangle(300, 400, 30, 170);
	cb.fillStroke();
	cb.setPatternFill(pat2, new GrayColor(0.9f));
	cb.rectangle(350, 400, 30, 40);
	cb.fillStroke();

	cb.sanityCheck();

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:74,代码来源:PatternTest.java

示例15: writeToPortableDocumentFormat

import com.lowagie.text.pdf.PdfTemplate; //导入依赖的package包/类
public static void writeToPortableDocumentFormat(Drawing drawing, OutputStream outputStream, float drawingWidth, float drawingHeight, float pageWidth, float pageHeight) throws DocumentException
{
	com.lowagie.text.Document document = new com.lowagie.text.Document();
	
	document.setPageSize(new com.lowagie.text.Rectangle(pageWidth, pageHeight));
	
	PdfWriter writer = PdfWriter.getInstance(document, outputStream);
	
	document.open();
	
	PdfContentByte cb = writer.getDirectContent();
	
	PdfTemplate tp = cb.createTemplate(drawingWidth, drawingHeight);
	
	DefaultFontMapper mapper = PdfFriend.getFontMapper();
	final DefaultDrawingContext drawingContext = (DefaultDrawingContext) DrawingContextFactory.getDrawingContext();
	Graphics2D g2 = null;
	
	if (BalloonEngineState.getInstance().isPreserveAccuracy())
		g2 = tp.createGraphicsShapes(drawingWidth, drawingHeight);
	else
		g2 = tp.createGraphics(drawingWidth, drawingHeight, mapper);
	
	drawingContext.setGraphics(g2);
	drawingContext.setTargetingPdf(true);
	drawingContext.setSelected(new Selection());
	drawingContext.setExportProfile(new SimpleExportProfile());
	
	drawing.drawOnto(drawingContext);
	
	Dimension dimension = new Dimension((int)drawingWidth, (int)drawingHeight);

	g2.dispose();
	cb.addTemplate(tp, 0, 0);
	document.close();
}
 
开发者ID:dhorlick,项目名称:balloonist,代码行数:37,代码来源:PdfFriend.java


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