Sophie

Sophie

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

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: Interactive Forms</title><meta name="Description" content="Step for step creation of an Acroform."><meta name="Keywords" content="PDF, JAVA, iText, examples, Acroforms, Interactive PDF forms, 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>Interactive Forms</h2><div id="content"><div id="sidebar"><a class="toc" href="./../index.html#forms">
							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="#acroform">Acroform</a></li><li><a href="#Fieldtypes">Field types</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/forms/FormPushButton.java">FormPushButton</a><br><div class="description">Generates a PDF with an Acroform containing a pushbutton</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/pushbutton.pdf">pushbutton.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormCheckbox.java">FormCheckbox</a><br><div class="description">Generates a PDF with an Acroform containing a checkbox</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/checkbox.pdf">checkbox.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormRadioButton.java">FormRadioButton</a><br><div class="description">Generates a PDF with an Acroform containing a radiobutton</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/radiobutton.pdf">radiobutton.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormTextField.java">FormTextField</a><br><div class="description">Generates a PDF with an Acroform containing a text field</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/textfield.pdf">textfield.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/SimpleRegistrationForm.java">SimpleRegistrationForm</a><br><div class="description">Generates a PdfPTable with some TextFields</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/SimpleRegistrationForm.pdf">SimpleRegistrationForm.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormCombo.java">FormCombo</a><br><div class="description">Generates a PDF with an Acroform containing a combobox</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/combo.pdf">combo.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormList.java">FormList</a><br><div class="description">Generates a PDF with an Acroform containing a list</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/list.pdf">list.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/TextFields.java">TextFields</a><br><div class="description">Generates a PDF with an Acroform containing text fields</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/TextFields.pdf">TextFields.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormSignature.java">FormSignature</a><br><div class="description">Generates a PDF with an Acroform containing a signature</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/signature.pdf">signature.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/forms/ListFields.java">ListFields</a><br><div class="description">Reads different pdf fields and lists the acrofields</div><div class="small">Argument(s):</div><ul><li>pushbutton.pdf</li><li>radiobutton.pdf</li><li>checkbox.pdf</li><li>textfield.pdf</li><li>SimpleRegistrationForm.pdf</li><li>combo.pdf</li><li>list.pdf</li><li>TextFields.pdf</li><li>signature.pdf</li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/forms/listfields.txt">listfields.txt</a></li></ul></div><div class="example"><div class="small">ANT script (all examples):</div><ul><li><a href="./../forms/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=15">
				Chapter 15:
			</a>Creating annotations and fields</li><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=16">
				Chapter 16:
			</a>Filling and signing AcroForms</li></ul></p>
		</div><a class="top" href="#top">Go to top of the page</a><a name="acroform"></a><div class="title">Acroform:</div><div xmlns="http://www.w3.org/1999/xhtml">
Extract from the Portable Document Format Reference Manual Version 1.6 (section 8.6 'Interactive Forms' page 634):
<blockquote>An <i>interactive form (PDF 1.2)</i>&#150;sometimes referred to as an <i>Acroform</i>&#150;is a collection
of <i>fields</i> for gathering information interactively from the user. A PDF document may contain any number of fields
appearing on any combination of pages, all of which make up a single, global interactive form spanning the entire document.</blockquote>
Do not confuse Acroforms with HTML forms (&lt;form&gt;-tags). They share some of the same purposes (e.g. getting userdata in an interactive way),
but they are completely different. You can't have more than one form in a PDF document. Fields in an acroform can be organized
hierarchically and can inherit attributes from their ancestors in the field hierarchy. Each field has a name
(See the Portable Document Format Reference Manual Version 1.6 section 8.6.2 'Field Dictionaries' page 638):
<blockquote>The <i>fully qualified filed name</i> is not explicitly defined
but is constructed from the partial field names of the field and all of its
ancestors. For a field with no parent, the partial and fully qualified names are the same.
For a field that is the child of another field, the fully qualified name is formed by appending
the child field's partial name to the parent's fully qualified name, separated by a period (.):
<pre class="commandline">  parent's_full_name.child's_partial_name</pre>
For example, if a field with the partial field name <span class="commandline">PersonalData</span> has a child whose partial name is <span class="commandline">Address</span>,
which in turn has a child with the partial name <span class="commandline">ZipCode</span>, the fully qualified name of this last field is
<pre class="commandline">PersonalData.Address.ZipCode</pre>
Thus, all fields descended from a common ancestor share the ancestor's fully qualified field name
as a common prefix in their own filly qualified names.</blockquote>
</div><a class="top" href="#top">Go to top of the page</a><a xmlns="" name="Fieldtypes"></a><div class="title">Field types:</div><div xmlns="http://www.w3.org/1999/xhtml">
The Portable Document Format Reference Manual Version 1.6
(section 8.6.3 'Field Types' page 647) distinguishes four types of fields:
<ol>
<li><b>Btn:</b> Button Fields</li>
<li><b>Tx:</b> Text Fields</li>
<li><b>Ch:</b> Choice</li>
<li><b>Sig:</b> Signature</li>
</ol>
<div class="subtitle">Button Fields</div>
<blockquote>Button fields represent interactive controls on the screen that the user can
manipulate with the mouse. They include pushbuttons, check boxes, and radio
buttons.</blockquote>
You can create all these button fields with the methods
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfFormField.html#createPushButton(com.lowagie.text.pdf.PdfWriter)">PdfFormField.createPushButton(PdfWriter writer)</a>,
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfFormField.html#createCheckBox(com.lowagie.text.pdf.PdfWriter)">PdfFormField.createCheckBox(PdfWriter writer)</a> and/or
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfFormField.html#createRadioButton(com.lowagie.text.pdf.PdfWriter,%20boolean)">PdfFormField.getRadioButton(PdfWriter writer, boolean noToggleToOff)</a>.
You are going to create a <a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAppearance.html">PdfAppearance</a> for every mouse operation:
<ul xmlns="http://www.w3.org/1999/xhtml">
<li><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#APPEARANCE_NORMAL">PdfAnnotation.APPEARANCE_NORMAL:</a> the normal appearance (no mouse action)</li>
<li xmlns="http://www.w3.org/1999/xhtml"><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#APPEARANCE_ROLLOVER">PdfAnnotation.APPEARANCE_ROLLOVER:</a> the appearance when the mouse is pointed at the button (mouseover)</li>
<li xmlns="http://www.w3.org/1999/xhtml"><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#APPEARANCE_DOWN">PdfAnnotation.APPEARANCE_APPEARANCE_DOWN:</a> the appearance when the button is pushed down</li>
</ul>
Remark: the syntax to create this appearance is the same as for
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfContentByte.html">PdfContentByte</a>
as described in <a href="./..//index.html#part4">Part IV</a> of the tutorial.
To visualize the button, you will set its widget annotations with
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfFormField.html#setWidget(com.lowagie.text.Rectangle,%20com.lowagie.text.pdf.PdfName)">setWidget(Rectangle rect, PdfName highlight)</a>. Parameter <span xmlns="http://www.w3.org/1999/xhtml" class="commandline">rect</span>
defines the position on the page, <span class="commandline">highlight</span> is one of the following values:
<ul>
<li><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#HIGHLIGHT_NONE">PdfAnnotation.HIGHLIGHT_NONE:</a> no highlighting.</li>
<li xmlns="http://www.w3.org/1999/xhtml"><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#HIGHLIGHT_INVERT">PdfAnnotation.HIGHLIGHT_INVERT:</a> invert the contents of the highlighted field.</li>
<li xmlns="http://www.w3.org/1999/xhtml"><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#HIGHLIGHT_OUTLINE">PdfAnnotation.HIGHLIGHT_OUTLINE:</a> invert the border of the field.</li>
<li xmlns="http://www.w3.org/1999/xhtml"><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#HIGHLIGHT_PUSH">PdfAnnotation.HIGHLIGHT_PUSH:</a> Display the down appearance, if any.
If no down appearance is defined, offset the contents of the annotation rectangle to appear as if it were being
pushed below the surface of the page.</li>
<li xmlns="http://www.w3.org/1999/xhtml"><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAnnotation.html#HIGHLIGHT_TOGGLE">PdfAnnotation.HIGHLIGHT_TOGGLE:</a> Same as PdfAnnotation.HIGHLIGHT_PUSH (which is preferred).</li>
</ul>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormPushButton.java">
						com.lowagie.examples.forms.FormPushButton</a><br>Generates a PDF with an Acroform containing a pushbutton: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/pushbutton.pdf">pushbutton.pdf</a><br></div>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormCheckbox.java">
						com.lowagie.examples.forms.FormCheckbox</a><br>Generates a PDF with an Acroform containing a checkbox: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/checkbox.pdf">checkbox.pdf</a><br></div>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormRadioButton.java">
						com.lowagie.examples.forms.FormRadioButton</a><br>Generates a PDF with an Acroform containing a radiobutton: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/radiobutton.pdf">radiobutton.pdf</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Text Fields</div>
<blockquote>Text fields are boxes or spaces in which the user can enter text from the keyboard.</blockquote>
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/TextField.html">TextField</a>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormTextField.java">
						com.lowagie.examples.forms.FormTextField</a><br>Generates a PDF with an Acroform containing a text field: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/textfield.pdf">textfield.pdf</a><br></div>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/forms/SimpleRegistrationForm.java">
						com.lowagie.examples.forms.SimpleRegistrationForm</a><br>Generates a PdfPTable with some TextFields: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/SimpleRegistrationForm.pdf">SimpleRegistrationForm.pdf</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Choice</div>
<blockquote>Choice fields contain several text items, at most one of which may be selected as
the field value. They include scrollable list boxes and combo boxes.</blockquote>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormList.java">
						com.lowagie.examples.forms.FormList</a><br>Generates a PDF with an Acroform containing a list: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/list.pdf">list.pdf</a><br></div>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormCombo.java">
						com.lowagie.examples.forms.FormCombo</a><br>Generates a PDF with an Acroform containing a combobox: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/combo.pdf">combo.pdf</a><br></div>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/forms/TextFields.java">
						com.lowagie.examples.forms.TextFields</a><br>Generates a PDF with an Acroform containing text fields: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/TextFields.pdf">TextFields.pdf</a><br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">Signature</div>
<blockquote>Signature fields represent electronic signatures for authenticating the identity of
a user and the validity of the document&rsquo;s contents.</blockquote>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/forms/FormSignature.java">
						com.lowagie.examples.forms.FormSignature</a><br>Generates a PDF with an Acroform containing a signature: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/forms/signature.pdf">signature.pdf</a><br></div>
</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:52
			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>