Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 927a1532fb070c51449654bb68b5bde2 > files > 428

itext-manual-2.0.8-0.0.2mdv2008.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>iText Tutorial: Images</title><meta name="Description" content="Deals with all types of images that are supported by iText"><meta name="Keywords" content="PDF, JAVA, iText, examples, tiff, gif, jpeg, Lowagie, Bruno"><link rel="stylesheet" href="./../../style.css" type="text/css"></head><body><a name="top" class="logo" href="http://www.lowagie.com/iText"><img src="http://www.lowagie.com/iText/images/logo.gif" border="0" alt="iText"></a><h1>Tutorial: iText by Example</h1><h2>Images</h2><div id="content"><div id="sidebar"><a class="toc" href="./../../index.html#objects_images">
							Table of Contents
						</a><div align="Center" class="small">Best viewed with:<br><script type="text/javascript"><!--
google_ad_client = "pub-0340380473790570";
google_ad_width = 180;
google_ad_height = 60;
google_ad_format = "180x60_as_rimg";
google_cpa_choice = "CAAQyaj8zwEaCIwcWMzeycafKMu293M";
//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div><div class="sidetitle">Sections:</div><ul><li><a href="#inaction">In the book</a></li><li><a href="#intro">Images</a></li><li><a href="#alignment">Image alignment</a></li><li><a href="#transformations">Image transformations</a></li><li><a href="#special">Some special features</a></li></ul><br><br><div class="sidetitle">Examples:</div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Images.java">Images</a><br><div class="description">Adds different formats of images to a document.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.bmp">iText.bmp</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/pngnow.png">pngnow.png</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.tif">iText.tif</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/getacro.gif">getacro.gif</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.wmf">iText.wmf</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Images.pdf">Images.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/RawData.java">RawData</a><br><div class="description">Using raw image data to construct an Image object.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/rawdata.pdf">rawdata.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/AwtImage.java">AwtImage</a><br><div class="description">Using a java.awt.Image object to construct an Image object.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/H.gif">H.gif</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/awt_image.pdf">awt_image.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Alignment.java">Alignment</a><br><div class="description">Alignment of images.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/vonnegut.gif">vonnegut.gif</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/hitchcock.png">hitchcock.png</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/alignment.pdf">alignment.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImagesAlignment.java">ImagesAlignment</a><br><div class="description">Alignment and wrapping of images.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/vonnegut.gif">vonnegut.gif</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/hitchcock.png">hitchcock.png</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/imagesAlignment.pdf">imagesAlignment.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImageSequence.java">ImageSequence</a><br><div class="description">Adds images to a document, once respecting the order in which they were added, once in the default order.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/getacro.gif">getacro.gif</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/inSequence.pdf">inSequence.pdf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/notInSequence.pdf">notInSequence.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/AbsolutePositions.java">AbsolutePositions</a><br><div class="description">Adding an Image at absolute positions.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/hitchcock.png">hitchcock.png</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/absolutepositions.pdf">absolutepositions.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Scaling.java">Scaling</a><br><div class="description">Scaling images.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/scaling.pdf">scaling.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/DvdCover.java">DvdCover</a><br><div class="description">Make a DVD Cover.</div><div class="small">Argument(s):</div><ul><li>dvdcover.pdf</li><li>My Sunflower Movie</li><li>808080</li><li>sunflower-front.jpg</li><li>sunflower-back.jpg</li></ul><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/sunflower-front.jpg">sunflower-front.jpg</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/sunflower-back.jpg">sunflower-back.jpg</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/dvdcover.pdf">dvdcover.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Rotating.java">Rotating</a><br><div class="description">Rotating images.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/rotating.pdf">rotating.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/AnnotatedImage.java">AnnotatedImage</a><br><div class="description">images and annotations.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.wmf">iText.wmf</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/annotated_images.pdf">annotated_images.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImageChunks.java">ImageChunks</a><br><div class="description">Images wrapped in a Chunk.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/pngnow.png">pngnow.png</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/imageChunks.pdf">imageChunks.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImageMasks.java">ImageMasks</a><br><div class="description">Applying a mask to an image.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/maskedImages.pdf">maskedImages.pdf</a></li></ul></div><div class="example"><div class="small">ANT script (all examples):</div><ul><li><a href="./../../objects/images/build.xml">
					build.xml
				</a></li></ul></div></div><div id="main"><a name="inaction"></a><div class="title">In the book:</div><div xmlns="http://www.w3.org/1999/xhtml" xmlns:site="http://www.lowagie.com/iText/site">
		<p xmlns=""><a href="http://itext.ugent.be/itext-in-action/"><img src="http://itext.ugent.be/img/lowagie_3d.jpg" border="0" align="right"></a>
			The examples in this free online tutorial will help you getting started
			with iText. Note that most examples are two years old.
			Some of the examples may be obsolete. Also the theory that
			comes with the examples isn't always 100% accurate.
			If you want more recent examples or if you want to know more
			about the theoretical background of	PDF and iText, please consult the book
			<a href="http://itext.ugent.be/itext-in-action/">
				"iText in Action".
			</a>
			Note that the first and the third chapter of the book
			can be downloaded for free from <a href="http://www.manning.com/affiliate/idevaffiliate.php?id=223_53">http://manning.com/lowagie/</a></p><p>
			More specifically:
			<ul><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=5">
				Chapter 5:
			</a>Inserting images</li></ul></p>
		</div><a class="top" href="#top">Go to top of the page</a><a name="intro"></a><div class="title">Images:</div><div xmlns="http://www.w3.org/1999/xhtml">
iText supports different kinds of image formats (even formats that aren't limited to images):
<ul>
<li><b>JPEG:</b> Joint Photographic Experts Group. Commonly used to refer to a lossy compression technique, reducing the size of a graphic file by as much as 96%. Usually the best file format for photographs on the Web.</li>
<li><b>GIF:</b> Graphic Interchange Format. A common format for image files, especially suitable for images containing large areas of the same color. GIF format files of simple images are often smaller than the same file would be if stored in JPEG format, but GIF format does not store photographic images as well as JPEG.</li>
<li><b>PNG:</b> Portable Network Graphics. A graphics format designed as the successor to GIF. It features compression, transparency, and progressive loading, like GIF, but it is free of patent restrictions.</li>
<li><b>TIFF:</b> Tagged Image File Format. A file format commonly used for digital scanned images.</li>
<li><b>BMP:</b> Windows bitmap. A common form of bitmap file in Microsoft Windows. Poorly supported by other operating systems and with limited support for colour.</li>
<li><b>WMF:</b> Windows Metafile Format. A vector graphics format for Windows-compatible computers used mostly for word-processing clip art.</li>
<li>basic support for <b>EPS:</b> Encapsulated PostScript; a graphics format that describes an image in the PostScript language.</li>
<li><b>java.awt.Image:</b> a JAVA object that is in the JDK from SUN</li>
<li><b>com.lowagie.text.pdf.PdfTemplate:</b> a sequence of PDF syntax, defined in a PdfTemplate can be wrapped in an Image</li>
<li><b>com.lowagie.text.pdf.Barcode:</b> an abstract class, check the <a xmlns="" href="./../../objects/images/tiff/index.html#barcode">implementing classes</a> to know what types of barcodes are supported</li>
</ul>
An Image can be created with one of the
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#getInstance(java.lang.String)">getInstance</a>-methods.
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html">Image</a> is an abstract class, so the getInstance method will detect the type of the given image (Jpeg, WMF,...) and return the corresponding object (<a href="http://itext.ugent.be/library/api/com/lowagie/text/Jpeg.html">Jpeg</a>, <a href="http://itext.ugent.be/library/api/com/lowagie/text/ImgWMF.html">ImgWMF</a>,...).
Lots of PDF libraries decompress images and change them into a Bitmap-like format before adding them to the PDF-file. This approach is avoided in iText, because it results in huge PDF files. The size of the resulting file is tens of times larger than the sum of the different images. This is not the case with iText. Identical Images are also reused (there's only one Image XObject) to save space.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Images.java">
						com.lowagie.examples.objects.images.Images</a><br>Adds different formats of images to a document.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Images.pdf">Images.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.bmp">iText.bmp</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/pngnow.png">pngnow.png</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.tif">iText.tif</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/getacro.gif">getacro.gif</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.wmf">iText.wmf</a><br></div>
The most common way to get an Image instance, is to use the path to the file (<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#getInstance(java.lang.String)">getInstance(java.lang.String)</a>) or the URL (<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#getInstance(java.net.URL)">getInstance(java.net.URL)</a>),
but you can also create an Image using the raw image data (for instance if you have an Image stored in a database):
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/RawData.java">
						com.lowagie.examples.objects.images.RawData</a><br>Using raw image data to construct an Image object.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/rawdata.pdf">rawdata.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a><br></div>
As iText is a JAVA library, the java.awt.Image object is also supported, but be careful when you are using this functionality on UNIX/Linux systems.
As you know you may need some special X requirements when using the java.awt.Toolkit for creating a java.awt.Image.
If you stick to com.lowagie.text.Image, you don't need this extra requirement; you can use com.lowagie.text.Image on every platform.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/AwtImage.java">
						com.lowagie.examples.objects.images.AwtImage</a><br>Using a java.awt.Image object to construct an Image object.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/awt_image.pdf">awt_image.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/H.gif">H.gif</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="alignment"></a><div class="title">Image alignment:</div><div xmlns="http://www.w3.org/1999/xhtml">
You can set the alignment of an image with
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#setAlignment(int)">setAlignment(int)</a>.
As parameter, you can use one of the self explaining constants
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#LEFT">LEFT</a>,
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#RIGHT">RIGHT</a> or
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#MIDDLE">MIDDLE</a>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Alignment.java">
						com.lowagie.examples.objects.images.Alignment</a><br>Alignment of images.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/alignment.pdf">alignment.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/vonnegut.gif">vonnegut.gif</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/hitchcock.png">hitchcock.png</a><br></div>
You can combine these alignment constants with
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#TEXTWRAP">TEXTWRAP</a> or
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#UNDERLYING">UNDERLYING</a>.
With the first constant, you can have the text wrapped around the image.
With the second constant, you specify that the text should cover the image.
Both constants are illustrated in the following example:
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImagesAlignment.java">
						com.lowagie.examples.objects.images.ImagesAlignment</a><br>Alignment and wrapping of images.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/imagesAlignment.pdf">imagesAlignment.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/vonnegut.gif">vonnegut.gif</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/hitchcock.png">hitchcock.png</a><br></div>
If you don't specify an absolute position for the image, iText tries to add it
at the position of the current pointer. However, it is not certain that there will
be enough space to add the image. In that case iText postpones adding the image and
adds other content first. If you really want the Image to be added at the moment
you are calling the add-method, you have to set the writer to use the strict image sequence:
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">writer.setStrictImageSequence(true);</pre>
Look at the example to see the difference between the default behaviour of iText
and the behaviour when the strict image sequence is set:
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImageSequence.java">
						com.lowagie.examples.objects.images.ImageSequence</a><br>Adds images to a document, once respecting the order in which they were added, once in the default order.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/inSequence.pdf">inSequence.pdf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/notInSequence.pdf">notInSequence.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/getacro.gif">getacro.gif</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="transformations"></a><div class="title">Image transformations:</div><div xmlns="http://www.w3.org/1999/xhtml">
You can also add an Image at an absolute position on the page, regardless of the other content.
In the chapter on <a xmlns="" href="./../../directcontent/coordinates/index.html#">coordinate systems</a>
the mechanisms of the transformation matrix that allow you to do this are explained in detail,
but maybe that's overkill. You probably don't need all that math. You will probably only need
simple translations, some scaling or basic rotating.<br xmlns="http://www.w3.org/1999/xhtml"><br>
<div class="subtitle">Translation</div>
One thing you must know about the coordinate system is the place of the origin:
it's in the lower left corner. The parameters of the method
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#setAbsolutePosition(float,%20float)">setAbsolutePosition(float, float)</a>
define the lowerleft corner of the image.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/AbsolutePositions.java">
						com.lowagie.examples.objects.images.AbsolutePositions</a><br>Adding an Image at absolute positions.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/absolutepositions.pdf">absolutepositions.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/hitchcock.png">hitchcock.png</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Scaling</div>
If you want to scale the image to a size of your own choice, use on of the
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#scaleAbsolute(float,%20float)">scaleAbsolute[Width|Height]</a>-methods.
If you want to scale the image to a certain percentage, use on of the
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#scalePercent(float)">scalePercent</a>-methods.<br xmlns="http://www.w3.org/1999/xhtml">
Note that the resolution of an image that is added without scaling will be 72dpi by default.
If an image is placed with a scaling of 50% the the resolution will be 144.
With lower scalings the resolution will increase because the pixels are the same but the size will be smaller.
To put a picture with 300dpi use a scaling of 72/300=24%. For instance: if you have a 5X5 inch image that
you scan at 300 dpi, the resultant image is 1500X1500 pixels (5X300 = 1500). When you place this image
in the pdf with a scaling of 24% (72/300 = 0.24), the image in the pdf will be 5X5 inch with 1500X1500 pixel at 300 dpi.
The image will always be 1500X1500 pixel whatever the size.
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Scaling.java">
						com.lowagie.examples.objects.images.Scaling</a><br>Scaling images.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/scaling.pdf">scaling.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a><br></div>
Another useful method for scaling is
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#scaleToFit(float,%20float)">scaleToFit</a>.
This method will scale the image to fit a rectangle, but will keep the XY-ratio intact.
Note that the Images used for the next example are not my own. They are used by courtesy of
<a xmlns="http://www.w3.org/1999/xhtml" href="http://www.bigfoto.com">www.bigfoto.com</a>.
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/DvdCover.java">
						com.lowagie.examples.objects.images.DvdCover</a> dvdcover.pdf My Sunflower Movie 808080 sunflower-front.jpg sunflower-back.jpg<br>Make a DVD Cover.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/dvdcover.pdf">dvdcover.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/sunflower-front.jpg">sunflower-front.jpg</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/sunflower-back.jpg">sunflower-back.jpg</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Rotating</div>
You can rotate an Image with one of these methods:
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#setRotation(float)">setRotation(float)</a> (angle in radians) or
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#setRotationDegrees(float)">setRotationDegrees(float)</a> (angle in degrees).
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/Rotating.java">
						com.lowagie.examples.objects.images.Rotating</a><br>Rotating images.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/rotating.pdf">rotating.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="special"></a><div class="title">Some special features:</div><div xmlns="http://www.w3.org/1999/xhtml">
<div class="subtitle">Clickable images</div>
If you want a clickable image or you want to add an annotation to an image, you have to construct an Annotation-object and add it to the image. You don't need to specify a position (you can take 0, 0, 0, 0). The position will be internally updated to fit the image.
See the method <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#setAnnotation(com.lowagie.text.Annotation)">setAnnotation(com.lowagie.text.Annotation)</a>
and the chapter on <a href="./../../objects/anchors/index.html#annotation">annotations</a>.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/AnnotatedImage.java">
						com.lowagie.examples.objects.images.AnnotatedImage</a><br>images and annotations.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/annotated_images.pdf">annotated_images.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/iText.wmf">iText.wmf</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Image inside a Chunk</div>
 In some cases it can be handy to wrap an image inside a <a xmlns="" href="./../../objects/chunk/index.html#">Chunk</a>. Just create a Chunk with an image and an offset
 with one of the <a href="http://itext.ugent.be/library/api/com/lowagie/text/Chunk.html#Chunk(com.lowagie.text.Image,%20float,%20float)">Chunk constructors</a> that take an Image as parameter.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImageChunks.java">
						com.lowagie.examples.objects.images.ImageChunks</a><br>Images wrapped in a Chunk.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/imageChunks.pdf">imageChunks.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/pngnow.png">pngnow.png</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Image masks</div>
You can create an Image that can be used as mask, making another image transparent:
<table border="0" cellpadding="0" cellspacing="1">
<tr>
    <td bgcolor="#c0c0c0" width="10"> </td>
    <td bgcolor="#c0c0c0" width="10"> </td>
    <td bgcolor="#000000" width="10"> </td>
    <td bgcolor="#000000" width="10"> </td>
    <td bgcolor="#000000" width="10"> </td>
    <td bgcolor="#000000" width="10"> </td>
    <td bgcolor="#c0c0c0" width="10"> </td>
    <td bgcolor="#c0c0c0" width="10"> </td>
    <td>3C</td>
</tr>
<tr>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td>7E</td>
</tr>
<tr>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td>E7</td>
</tr>
<tr>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td>C3</td>
</tr>
<tr>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td>C3</td>
</tr>
<tr>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td>E7</td>
</tr>
<tr>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td>7E</td>
</tr>
<tr>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#000000"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td bgcolor="#c0c0c0"> </td>
    <td>3C</td>
</tr>
</table>
This image has a size of 8 by 8 pixels, 1 component and 1 byte per component.
Using the method <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Image.html#makeMask()">makeMask()</a>, it can be turned into a mask:
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">byte maskr[] =
   {(byte)0x3c,
    (byte)0x7e,
    (byte)0xe7,
    (byte)0xc3,
    (byte)0xc3,
    (byte)0xe7,
    (byte)0x7e,
    (byte)0x3c};
Image mask = Image.getInstance(8, 8, 1, 1, maskr);
mask.makeMask();
mask.setInvertMask(true);</pre>
We can use this mask for explicit masking to clip some parts of an image:
<pre class="commandline">PdfContentByte cb = writer.getDirectContent();
Image image = Image.getInstance("vonnegut.gif");
image.setImageMask(mask);</pre>
In the chapter on
<a xmlns="" href="./../../directcontent/colors/index.html#patterns">colors and patterns</a>,
the concept of stencil masks is discussed. You can use the mask we created from an Image for stencil masking:
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">PdfContentByte cb = writer.getDirectContent();
cb.setRGBColorFill(255, 0, 0);
cb.addImage(mask, mask.scaledWidth() * 8, 0, 0, mask.scaledHeight() * 8, 100, 400);</pre>
(Note that for the addImage method, you will need to read more about <a xmlns="" href="./../../directcontent/coordinates/index.html#">coordinate systems</a>...)
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/ImageMasks.java">
						com.lowagie.examples.objects.images.ImageMasks</a><br>Applying a mask to an image.: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/maskedImages.pdf">maskedImages.pdf</a><br>
						External resources for this example:
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/images/otsoe.jpg">otsoe.jpg</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Selected examples</div>
EPS, Tiff and barcode functionality is discussed in a <a xmlns="" href="./../../objects/images/tiff/index.html#">separate chapter</a>.
</div><a class="top" href="#top">Go to top of the page</a><div id="footer" xmlns="http://www.w3.org/1999/xhtml">
			Page Updated: 2006/09/17 10:13:59
			Copyright &copy; 1999-2005
			Bruno Lowagie<br><a href="http://www.lowagie.com/iText/">iText</a> is a Free Java-Pdf library by Bruno Lowagie and Paulo Soares.
		</div></div></div><div class="commercial"><br><script type="text/javascript"><!--
google_ad_client = "pub-0340380473790570";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="";
google_ad_type = "text_image";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "1B09BD";
google_color_url = "100670";
google_color_text = "707070";
//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br><br><div class="subtitle">Amazon books:</div><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=8&l=as1&asins=1932394796&fc1=000000&lc1=0000ff&bc1=&lt1=_blank&IS2=1&bg1=ffffff&f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="Center"></iframe>');
//--></script><a xmlns="" href="http://www.amazon.co.uk/exec/obidos/ASIN/1932394796/catloogjecom-21" class="amazonlinks">
			amazon.co.uk-link
		</a><br><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=10&l=st1&mode=books&search=GIF&=1&fc1=&lc1=&lt1=&bg1=&f=ifr" width="120" height="460" border="0" frameborder="0" style="border:none;" scrolling="no" marginwidth="0" marginheight="0"></iframe>');
//--></script><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=10&l=st1&mode=books&search=JPEG&=1&fc1=&lc1=&lt1=&bg1=&f=ifr" width="120" height="460" border="0" frameborder="0" style="border:none;" scrolling="no" marginwidth="0" marginheight="0"></iframe>');
//--></script><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=10&l=st1&mode=books&search=TIFF&=1&fc1=&lc1=&lt1=&bg1=&f=ifr" width="120" height="460" border="0" frameborder="0" style="border:none;" scrolling="no" marginwidth="0" marginheight="0"></iframe>');
//--></script><br></div></body></html>