Sophie

Sophie

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

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: Frequently Asked Questions</title><meta name="Description" content="This is a basic technical reference that answers some frequently asked questions."><meta name="Keywords" content="PDF, JAVA, iText, examples, FAQ, 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>Frequently Asked Questions</h2><div id="content"><div id="sidebar"><a class="toc" href="./../../index.html#general_faq">
							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="#measurements">Measurements</a></li><li><a href="#newpage">How to create a new page in iText</a></li><li><a href="#version">iText Version</a></li><li><a href="#pdfversion">PDF Version</a></li><li><a href="#portability">Why are there some strange characters in the PDF Header?</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/general/faq/Measurements.java">Measurements</a><br><div class="description">Demonstrates the measurement system (points, inches, centimeters)</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/Measurements.pdf">Measurements.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/NewPage.java">NewPage</a><br><div class="description">Shows how to go to a new page or insert a blank page</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/NewPage.pdf">NewPage.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/iTextVersion.java">iTextVersion</a><br><div class="description">Shows the iText version that was used to generate this example</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/version.pdf">version.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/PdfVersion.java">PdfVersion</a><br><div class="description">Change the PDF version of a document</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/pdfversion.pdf">pdfversion.pdf</a></li></ul></div><div class="example"><div class="small">ANT script (all examples):</div><ul><li><a href="./../../general/faq/build.xml">
					build.xml
				</a></li></ul></div></div><div id="main"><font color="#FF0000" size="+2">UNDER CONSTRUCTION</font><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=2">
				Chapter 2:
			</a>PDF engine jump-start</li><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=3">
				Chapter 3:
			</a>PDF, why and when</li><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=10">
				Chapter 10:
			</a>Constructing and painting paths</li><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=14">
				Chapter 14:
			</a>Automating PDF creation</li></ul></p>
		</div><a class="top" href="#top">Go to top of the page</a><a name="measurements"></a><div class="title">Measurements:</div><div xmlns="http://www.w3.org/1999/xhtml">
If you want to create a Rectangle (PageSize), define a margin, choose a font size
or add something at an absolute place, you might wonder what measurement unit
is used: centimeters, inches, points or pixels. In fact, the default measurement
system roughly corresponds to the various definitions of the typographic unit of measurement
known as the point. There are 72 points in 1 inch.<br>
If you want to create a rectangle in PDF that has the size of an A4-page, you have
to calculate the number of points:<ul>
<li>21 cm / 2.54 = 8.2677 inch</li>
<li>8.2677 * 72 = 595 points</li>
<li>29.7 cm / 2.54 = 11.6929 inch</li>
<li>11.6929 * 72 = 842 points</li>
</ul>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/Measurements.java">
						com.lowagie.examples.general.faq.Measurements</a><br>Demonstrates the measurement system (points, inches, centimeters): see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/Measurements.pdf">Measurements.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="newpage"></a><div class="title">How to create a new page in iText:</div><div xmlns="http://www.w3.org/1999/xhtml">
It strikes me how many times this question is asked on the mailing-list.
The method you need to create a new page isn't that cryptic:
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#newPage()">document.newPage()</a>.
Of course, there are some little caveats:
<ul xmlns="http://www.w3.org/1999/xhtml"><li>If you are construction an Object such as <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Section.html">Section</a>,
you can't just invoke <a href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html">newPage()</a> on the document;
you should tell the object, that you want to go to the next page.
In this case, you should add a <a href="http://itext.ugent.be/library/api/com/lowagie/text/Chunk.html#NEXTPAGE">Chunk.NEXPAGE</a>
to the object.</li>
<li xmlns="http://www.w3.org/1999/xhtml">If you invoke <span class="commandline">newPage</span>
and the current page is blank, no new page will be added. You can insert blank pages if you
add something 'invisible' to the blank page. In the example below, a
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Chunk.html#NEWLINE">Chunk.NEWLINE</a> is added.
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">document.newPage();
document.add(Chunk.NEWLINE);
document.newPage();</pre>
Or you can tell the writer the page isn't empty (allthough it IS). This is done with the
method <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#setPageEmpty(boolean)">setPageEmpty</a>
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">document.newPage();
writer.setPageEmpty(false);
document.newPage();</pre></li></ul>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/NewPage.java">
						com.lowagie.examples.general.faq.NewPage</a><br>Shows how to go to a new page or insert a blank page: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/NewPage.pdf">NewPage.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="version"></a><div class="title">iText Version:</div><div xmlns="http://www.w3.org/1999/xhtml">
If you file a bugreport or post a question to the <a href="http://news.gmane.org/gmane.comp.java.lib.itext.general">mailing-list</a>,
one of the first questions you will be asked is:<br><i>What version of iText are you using?</i><br>
There are two ways you can find out the answer. You can open the PDF file in Acrobat and
go to the window File -&gt; Document Properties... Under 'Description' you'll see what library/product
was used as 'PDF Producer'. In the screenshot below, it was <i>iText1.1.2 by lowagie.com (based on itext-paulo-144)</i>.
You can always check the most recent releasenumber on the <a href="http://www.lowagie.com/iText/download.html">iText download page</a>.<br>
<img xmlns="" border="0" src="./../../images/metadata.gif" alt="Document Properties Window"><br xmlns="http://www.w3.org/1999/xhtml">
Of course, if a post-processing tool was used, another product will be listed as
PDF Producer. In that case, you can ask the library programmatically for its version
with <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#getVersion()">Document.getVersion()</a>
and send the output to the System.out or System.err.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/iTextVersion.java">
						com.lowagie.examples.general.faq.iTextVersion</a><br>Shows the iText version that was used to generate this example: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/version.pdf">version.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="pdfversion"></a><div class="title">PDF Version:</div><div xmlns="http://www.w3.org/1999/xhtml">
Read the Portable Document Format Reference Manual Version 1.6 (section 3.4.1 'File Header' page 68):
<blockquote>The first line of a PDF file is a header identifying the version of the PDF specification
to which the file conforms. For a file conforming to PDF version 1.5, the
header should be
<pre class="commandline">%PDF&minus;1.5</pre></blockquote>
iText generated documents have version PDF-1.4 by default, but you can change
the version with the method <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#setPdfVersion(char)">setPdfVersion</a>.
The parameter can be
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#VERSION_1_2">PdfWriter.VERSION_1_2</a>,
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#VERSION_1_3">PdfWriter.VERSION_1_3</a>,
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#VERSION_1_4">PdfWriter.VERSION_1_4</a>,
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#VERSION_1_5">PdfWriter.VERSION_1_5</a> or
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#VERSION_1_6">PdfWriter.VERSION_1_6</a>.
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">writer.setPdfVersion(PdfWriter.VERSION_1_2);</pre>
Remark: this only changes the header (iText doesn't keep the version in the catalog yet).
If you change the version number to a lower version, you are responsible for
making sure that you don't use newer features.
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/PdfVersion.java">
						com.lowagie.examples.general.faq.PdfVersion</a><br>Change the PDF version of a document: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/faq/pdfversion.pdf">pdfversion.pdf</a><br></div>
<img border="0" src="./../../images/pdfversion.gif" alt="Document Properties Window">
</div><a class="top" href="#top">Go to top of the page</a><a name="portability"></a><div class="title">Why are there some strange characters in the PDF Header?:</div><div xmlns="http://www.w3.org/1999/xhtml">
Read the Portable Document Format Reference Manual Version 1.6 (section 3.4.1 'File Header' page 68):
<blockquote>If a PDF file contains binary data, as most do,
it is recommended that the header line be immediately followed by a
comment line containing at least four binary characters&mdash;that is, characters whose
codes are 128 or greater. This ensures proper behavior of file transfer applications
that inspect data near the beginning of a file to determine whether to treat the file's
contents as text or as binary.</blockquote>
iText adds these 4 binary characters automatically. The second line of an iText generated PDF file always looks like this when opened in a text editor:
<pre class="commandline">%&acirc;&atilde;&Iuml;&Oacute;</pre>
</div><a class="top" href="#top">Go to top of the page</a><div id="footer">
			Page Updated: 2006/09/17 10:13:58
			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=8&l=as1&asins=0321304748&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 href="http://www.amazon.co.uk/exec/obidos/ASIN/0321304748/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=PDF&=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>