Java Code Examples for com.lowagie.text.Image#getInstance()

The following examples show how to use com.lowagie.text.Image#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlignmentTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Demonstrates the alignment method.
 */
@Test
public void main() throws Exception {
	// step 1: creation of a document-object
	Document document = new Document();
	// step 2: creation of a writer
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("alignment.pdf"));

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

	Image gif = Image.getInstance(PdfTestBase.RESOURCES_DIR + "vonnegut.gif");
	gif.setAlignment(Image.RIGHT);
	Image jpeg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	jpeg.setAlignment(Image.MIDDLE);
	Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
	png.setAlignment(Image.LEFT);

	document.add(gif);
	document.add(jpeg);
	document.add(png);

	// step 5: we close the document
	document.close();
}
 
Example 2
Source File: InvestmentSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document; 
    pdf.setPageSize(PageSize.A3); 
    pdf.open();  
     
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Investment Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
 
Example 3
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeMemoryInformations(MemoryInformations memoryInformations)
		throws BadElementException, IOException {
	addCell(memoryInformations.getMemoryDetails().replace(" Mo", ' ' + getString("Mo")));
	final long usedPermGen = memoryInformations.getUsedPermGen();
	if (usedPermGen > 0) {
		// perm gen est à 0 sous jrockit
		final long maxPermGen = memoryInformations.getMaxPermGen();
		addCell(getString("Memoire_Perm_Gen") + ':');
		if (maxPermGen > 0) {
			final Phrase permGenPhrase = new Phrase(
					integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo")
							+ DIVIDE + integerFormat.format(maxPermGen / 1024 / 1024) + ' '
							+ getString("Mo") + BAR_SEPARATOR,
					cellFont);
			final Image permGenImage = Image.getInstance(
					Bar.toBarWithAlert(memoryInformations.getUsedPermGenPercentage()), null);
			permGenImage.scalePercent(50);
			permGenPhrase.add(new Chunk(permGenImage, 0, 0));
			currentTable.addCell(permGenPhrase);
		} else {
			addCell(integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo"));
		}
	}
}
 
Example 4
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {  
    Document pdf = (Document) document;  
    pdf.setPageSize(PageSize.A3);
    pdf.open(); 
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String logo = servletContext.getRealPath("") + File.separator +"resources" + File.separator + "images" + File.separator +"logo" + File.separator + "logo.png";  
    Image image=Image.getInstance(logo);
    image.scaleAbsolute(100f, 50f);
    pdf.add(image); 
    // add a couple of blank lines
       pdf.add( Chunk.NEWLINE );
       pdf.add( Chunk.NEWLINE );
    Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
    fontbold.setColor(55, 55, 55);;
    pdf.add(new Paragraph("Account Summary",fontbold));
    // add a couple of blank lines
    pdf.add( Chunk.NEWLINE );
    pdf.add( Chunk.NEWLINE );
}
 
Example 5
Source File: PDFPrinter.java    From unitime with Apache License 2.0 5 votes vote down vote up
public A(java.awt.Image image) {
	try {
		if (image instanceof BufferedImage)
			iBufferedImage = (BufferedImage)image;
		iImage = Image.getInstance(image, Color.WHITE);
	} catch (Exception e) {}
}
 
Example 6
Source File: SoftMaskTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Demonstrates the Transparency functionality.
 */
@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 a writer
	PdfWriter writer = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("softmask.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: content
	PdfContentByte cb = writer.getDirectContent();
	String text = "text ";
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	document.add(new Paragraph(text));
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR	+ "otsoe.jpg");
	img.setAbsolutePosition(100, 550);
	byte gradient[] = new byte[256];
	for (int k = 0; k < 256; ++k) {
		gradient[k] = (byte) k;
	}
	Image smask = Image.getInstance(256, 1, 1, 8, gradient);
	smask.makeMask();
	img.setImageMask(smask);
	cb.addImage(img);
	cb.sanityCheck();
	// step 5: we close the document
	document.close();
}
 
Example 7
Source File: PdfTimetableGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception  {
	if (text==null) return;
       if (text.indexOf("<span")>=0)
           text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
       Font font = PdfFont.getFont(bold);
	BaseFont bf = font.getBaseFont();
	float width = bf.getWidthPoint(text, font.getSize());
	PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
	template.beginText();
	template.setColorFill(Color.BLACK);
	template.setFontAndSize(bf, font.getSize());
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(font.getSize() + 2);
	//make an Image object from the template
	Image img = Image.getInstance(template);
	img.setRotationDegrees(270);
	//embed the image in a Chunk
	Chunk ck = new Chunk(img, 0, 0);
	
	if (cell.getPhrase()==null) {
		cell.setPhrase(new Paragraph(ck));
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	} else {
		cell.getPhrase().add(ck);
	}
}
 
Example 8
Source File: ImageAreaLayout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void initialize( ) throws BirtException
{
	// choose the layout manager
	reader = new ImageReader( content, context.getSupportedImageFormats( ) );
	int result = reader.read( );
	switch ( result )
	{
		case ImageReader.RESOURCE_UNREACHABLE:
			// display the alt text or prompt object not accessible.
			layout = createAltTextLayout( ImageReader.RESOURCE_UNREACHABLE );
			break;
		case ImageReader.UNSUPPORTED_OBJECTS:
			// display the alt text or prompt unsupported objects.
			layout = createAltTextLayout( ImageReader.UNSUPPORTED_OBJECTS );
			break;
		case ImageReader.OBJECT_LOADED_SUCCESSFULLY:
			//the object is accessible.
			if ( reader.getType( ) == ImageReader.TYPE_IMAGE_OBJECT
					|| reader.getType( ) == ImageReader.TYPE_CONVERTED_SVG_OBJECT )
			{
				try
				{
					imageObject = Image.getInstance( reader.getByteArray( ) );
				}
				catch ( Exception e )
				{
					logger.log( Level.WARNING, e.getLocalizedMessage( ) );
				}
				// unrecognized image formats.
				if ( imageObject == null )
				{
					layout = createAltTextLayout( ImageReader.UNSUPPORTED_OBJECTS );
					break;
				}
			}
			layout = new ConcreteImageLayout( context, parent, content,
					reader.getByteArray( ) );
			break;
	}
}
 
Example 9
Source File: PdfContext.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
public Image getImage(String path) {
	try {
		URL url = getClass().getResource(path);
		if (url == null) {
			url = Utilities.toURL(path);
		}
		return Image.getInstance(url);
	} catch (Exception e) { // NOSONAR
		log.warn("could not fetch image", e);
		return null;
	}
}
 
Example 10
Source File: ImagesTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * General Images example
 */
@Test
public void main() throws Exception {

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

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

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

	// step 4:
	document.add(new Paragraph("A picture of my dog: otsoe.jpg"));
	Image jpg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	document.add(jpg);
	document.add(new Paragraph("getacro.gif"));
	Image gif = Image.getInstance(PdfTestBase.RESOURCES_DIR + "getacro.gif");
	document.add(gif);
	document.add(new Paragraph("pngnow.png"));
	Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png");
	document.add(png);
	document.add(new Paragraph("iText.bmp"));
	Image bmp = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.bmp");
	document.add(bmp);
	document.add(new Paragraph("iText.wmf"));
	Image wmf = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.wmf");
	document.add(wmf);
	document.add(new Paragraph("iText.tif"));
	Image tiff = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.tif");
	document.add(tiff);

	// step 5: we close the document
	document.close();
}
 
Example 11
Source File: PdfCell.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds an image to this Cell.
 *
 * @param i           the image to add
 * @param left        the left border
 * @param right       the right border
 * @param extraHeight extra height to add above image
 * @param alignment   horizontal alignment (constant from Element class)
 * @return the height of the image
 */

private float addImage(Image i, float left, float right, float extraHeight, int alignment) {
    Image image = Image.getInstance(i);
    if (image.getScaledWidth() > right - left) {
        image.scaleToFit(right - left, Float.MAX_VALUE);
    }
    flushCurrentLine();
    if (line == null) {
        line = new PdfLine(left, right, alignment, leading);
    }
    PdfLine imageLine = line;

    // left and right in chunk is relative to the start of the line
    right = right - left;
    left = 0f;

    if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
        left = right - image.getScaledWidth();
    } else if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) {
        left = left + ((right - left - image.getScaledWidth()) / 2f);
    }
    Chunk imageChunk = new Chunk(image, left, 0);
    imageLine.add(new PdfChunk(imageChunk, null));
    addLine(imageLine);
    return imageLine.height();
}
 
Example 12
Source File: BarcodeDatamatrix.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Gets an <CODE>Image</CODE> with the barcode. A successful call to the method <CODE>generate()</CODE>
 * before calling this method is required.
 * @return the barcode <CODE>Image</CODE>
 * @throws BadElementException on error
 */    
public Image createImage() throws BadElementException {
    if (image == null)
        return null;
    byte g4[] = CCITTG4Encoder.compress(image, width + 2 * ws, height + 2 * ws);
    return Image.getInstance(width + 2 * ws, height + 2 * ws, false, Image.CCITTG4, 0, g4, null);
}
 
Example 13
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeTomcatInformations(List<TomcatInformations> tomcatInformationsList)
		throws BadElementException, IOException {
	for (final TomcatInformations tomcatInformations : tomcatInformationsList) {
		if (tomcatInformations.getRequestCount() <= 0) {
			continue;
		}
		addCell("Tomcat " + tomcatInformations.getName() + ':');
		// rq: on n'affiche pas pour l'instant getCurrentThreadCount
		final int currentThreadsBusy = tomcatInformations.getCurrentThreadsBusy();
		final String equal = " = ";
		final Phrase phrase = new Phrase(getString("busyThreads") + equal
				+ integerFormat.format(currentThreadsBusy) + DIVIDE
				+ integerFormat.format(tomcatInformations.getMaxThreads()) + BAR_SEPARATOR,
				cellFont);
		final Image threadsImage = Image.getInstance(Bar.toBarWithAlert(
				100d * currentThreadsBusy / tomcatInformations.getMaxThreads()), null);
		threadsImage.scalePercent(50);
		phrase.add(new Chunk(threadsImage, 0, 0));

		phrase.add(new Chunk('\n' + getString("bytesReceived") + equal
				+ integerFormat.format(tomcatInformations.getBytesReceived()) + '\n'
				+ getString("bytesSent") + equal
				+ integerFormat.format(tomcatInformations.getBytesSent()) + '\n'
				+ getString("requestCount") + equal
				+ integerFormat.format(tomcatInformations.getRequestCount()) + '\n'
				+ getString("errorCount") + equal
				+ integerFormat.format(tomcatInformations.getErrorCount()) + '\n'
				+ getString("processingTime") + equal
				+ integerFormat.format(tomcatInformations.getProcessingTime()) + '\n'
				+ getString("maxProcessingTime") + equal
				+ integerFormat.format(tomcatInformations.getMaxTime())));
		currentTable.addCell(phrase);
	}
}
 
Example 14
Source File: Barcode.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** Creates an <CODE>Image</CODE> with the barcode.
 * @param cb the <CODE>PdfContentByte</CODE> to create the <CODE>Image</CODE>. It
 * serves no other use
 * @param barColor the color of the bars. It can be <CODE>null</CODE>
 * @param textColor the color of the text. It can be <CODE>null</CODE>
 * @return the <CODE>Image</CODE>
 * @see #placeBarcode(PdfContentByte cb, Color barColor, Color textColor)
 */    
public Image createImageWithBarcode(PdfContentByte cb, Color barColor, Color textColor) {
    try {
        return Image.getInstance(createTemplateWithBarcode(cb, barColor, textColor));
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 15
Source File: PdfCell.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Adds an image to this Cell.
 *
 * @param i the image to add
 * @param left the left border
 * @param right the right border
 * @param extraHeight extra height to add above image
 * @param alignment horizontal alignment (constant from Element class)
 * @return the height of the image
 */

private float addImage(Image i, float left, float right, float extraHeight, int alignment) {
	Image image = Image.getInstance(i);
	if (image.getScaledWidth() > right - left) {
		image.scaleToFit(right - left, Float.MAX_VALUE);
	}
	flushCurrentLine();
	if (line == null) {
		line = new PdfLine(left, right, alignment, leading);
	}
	PdfLine imageLine = line;

	// left and right in chunk is relative to the start of the line
	right = right - left;
	left = 0f;

	if ((image.getAlignment() & Image.RIGHT) == Image.RIGHT) {
		left = right - image.getScaledWidth();
	} else if ((image.getAlignment() & Image.MIDDLE) == Image.MIDDLE) {
		left = left + (right - left - image.getScaledWidth()) / 2f;
	}
	Chunk imageChunk = new Chunk(image, left, 0);
	imageLine.add(new PdfChunk(imageChunk, null));
	addLine(imageLine);
	return imageLine.height();
}
 
Example 16
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
private InternalImageProcessorResult processImageFillFrame(String rendererId, DataRenderable renderer) throws JRException
{
	Image image = null;
	
	if (printImage.isUsingCache() && loadedImagesMap.containsKey(rendererId))
	{
		image = loadedImagesMap.get(rendererId);
	}
	else
	{
		try
		{
			image = Image.getInstance(renderer.getData(jasperReportsContext));
			imageTesterPdfContentByte.addImage(image, 10, 0, 0, 10, 0, 0);
		}
		catch (Exception e)
		{
			throw new JRException(e);
		}

		if (printImage.isUsingCache())
		{
			loadedImagesMap.put(rendererId, image);
		}
	}

	switch (printImage.getRotation())
	{
		case LEFT :
		{
			image.scaleAbsolute(availableImageHeight, availableImageWidth);
			image.setRotationDegrees(90);
			break;
		}
		case RIGHT :
		{
			image.scaleAbsolute(availableImageHeight, availableImageWidth);
			image.setRotationDegrees(-90);
			break;
		}
		case UPSIDE_DOWN :
		{
			image.scaleAbsolute(availableImageWidth, availableImageHeight);
			image.setRotationDegrees(180);
			break;
		}
		case NONE :
		default :
		{
			image.scaleAbsolute(availableImageWidth, availableImageHeight);
		}
	}
	
	return 
		new InternalImageProcessorResult(
			new Chunk(image, 0, 0), 
			image.getScaledWidth(), 
			image.getScaledHeight(),
			0,
			0
			);
}
 
Example 17
Source File: AddWatermarkPageNumbersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
    * Reads the pages of an existing PDF file, adds pagenumbers and a watermark.

    */
@Test
   public  void main() throws Exception {
           // we create a reader for a certain document
           PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR +"ChapterSection.pdf");
           int n = reader.getNumberOfPages();
           // we create a stamper that will copy the document to a new file
           PdfStamper stamp = new PdfStamper(reader,PdfTestBase.getOutputStream("watermark_pagenumbers.pdf"));
           // adding some metadata
           HashMap<String, String> moreInfo = new HashMap<String, String>();
           moreInfo.put("Author", "Bruno Lowagie");
           stamp.setMoreInfo(moreInfo);
           // adding content to each page
           int i = 0;
           PdfContentByte under;
           PdfContentByte over;
           Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR +"watermark.jpg");
           BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
           img.setAbsolutePosition(200, 400);
           while (i < n) {
           	i++;
           	// watermark under the existing page
           	under = stamp.getUnderContent(i);
           	under.addImage(img);
           	// text over the existing page
           	over = stamp.getOverContent(i);
           	over.beginText();
           	over.setFontAndSize(bf, 18);
           	over.setTextMatrix(30, 30);
           	over.showText("page " + i);
           	over.setFontAndSize(bf, 32);
           	over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE", 230, 430, 45);
           	over.endText();
           }
           // adding an extra page
           stamp.insertPage(1, PageSize.A4);
           over = stamp.getOverContent(1);
       	over.beginText();
       	over.setFontAndSize(bf, 18);
           over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE OF AN EXISTING PDF DOCUMENT", 30, 600, 0);
           over.endText();
           // adding a page from another document
           PdfReader reader2 = new PdfReader(PdfTestBase.RESOURCES_DIR +"SimpleAnnotations1.pdf");
           under = stamp.getUnderContent(1);
           under.addTemplate(stamp.getImportedPage(reader2, 3), 1, 0, 0, 1, 0, 0);
           // closing PdfStamper will generate the new PDF file
           stamp.close();
   }
 
Example 18
Source File: LayersTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Draws different things into different layers.
 */
@Test
public void main() throws Exception {


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

	
	// step 2: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document,	PdfTestBase.getOutputStream("layers.pdf"));

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

	// step 4:

	// high level
	Paragraph p = new Paragraph();
	for (int i = 0; i < 100; i++)
		p.add(new Chunk("Blah blah blah blah blah. "));
	document.add(p);
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
			+ "hitchcock.png");
	img.setAbsolutePosition(100, 500);
	document.add(img);

	// low level
	PdfContentByte cb = writer.getDirectContent();
	PdfContentByte cbu = writer.getDirectContentUnder();
	cb.setRGBColorFill(0xFF, 0xFF, 0xFF);
	cb.circle(250.0f, 500.0f, 50.0f);
	cb.fill();
	cb.sanityCheck();

	cbu.setRGBColorFill(0xFF, 0x00, 0x00);
	cbu.circle(250.0f, 500.0f, 100.0f);
	cbu.fill();
	cbu.sanityCheck();

	// step 5: we close the document
	document.close();
}
 
Example 19
Source File: ImagesURLTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Images example with a complete path to the images.
 */
@Test
public void main() throws Exception {

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

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

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

	File current = new File(".");
	File resources = new File(current, PdfTestBase.RESOURCES_DIR);

	// step 4:
	document.add(new Paragraph("A picture of my dog: otsoe.jpg"));
	File otsoe = new File(resources, "otsoe.jpg");
	Image jpg = Image.getInstance(new URL("file:///" + otsoe.getAbsolutePath()));
	document.add(jpg);

	document.add(new Paragraph("getacro.gif"));
	File getacro = new File(resources, "getacro.gif");
	Image gif = Image.getInstance(new URL("file:///" + getacro.getAbsolutePath()));
	document.add(gif);

	document.add(new Paragraph("pngnow.png"));
	File pngNow = new File(resources, "pngnow.png");
	Image png = Image.getInstance(new URL("file:///" + pngNow.getAbsolutePath()));
	document.add(png);

	document.add(new Paragraph("iText.bmp"));
	File itextBmp = new File(resources, "iText.bmp");
	Image bmp = Image.getInstance(new URL("file:///" + itextBmp.getAbsolutePath()));
	document.add(bmp);

	document.add(new Paragraph("iText.wmf"));
	File itextWmf = new File(resources, "iText.wmf");
	Image wmf = Image.getInstance(new URL("file:///" + itextWmf.getAbsolutePath()));
	document.add(wmf);

	document.add(new Paragraph("iText.tif"));
	File itextTif = new File(resources, "iText.tif");
	Image tiff = Image.getInstance(new URL("file:///" + itextTif.getAbsolutePath()));
	document.add(tiff);

	// step 5: we close the document
	document.close();
}
 
Example 20
Source File: PDFPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void drawImage( String imageId, byte[] imageData,
		String extension, float imageX, float imageY, float height,
		float width, String helpText, Map params ) throws Exception
{
	// Flash
	if ( FlashFile.isFlash( null, null, extension ) )
	{
		embedFlash( null, imageData, imageX, imageY, height, width,
				helpText, params );
		return;
	}

	// Cached Image
	PdfTemplate template = null;
	if ( imageId != null )
	{
		if ( pageDevice.getImageCache( ).containsKey( imageId ) )
		{
			template = pageDevice.getImageCache( ).get( imageId );
		}
		if ( template != null )
		{
			drawImage( template, imageX, imageY, height, width, helpText );
			return;
		}
	}

	// Not cached yet
	if ( SvgFile.isSvg( null, null, extension ) )
	{
		template = generateTemplateFromSVG( null, imageData, imageX,
				imageY, height, width, helpText );
	}
	else
	{
		// PNG/JPG/BMP... images:
		Image image = Image.getInstance( imageData );
		if ( imageId == null )
		{
			// image without imageId, not able to cache.
			drawImage( image, imageX, imageY, height, width, helpText );
			return;
		}
		template = contentByte.createTemplate( width, height );
		template.addImage( image, width, 0, 0, height, 0, 0 );
	}
	// Cache the image
	if ( imageId != null && template != null )
	{
		pageDevice.getImageCache( ).put( imageId, template );
	}
	if ( template != null )
	{
		drawImage( template, imageX, imageY, height, width, helpText );
	}
}