Introduction:
iText is a library that allows developers to extend the capabilities of their web server (and other JAVA) applications with dynamic PDF document generation. In this tutorial, you will find lots of standalone examples to learn how to use most of the iText functionality and features. It should be easy to integrate most of the solutions in a Servlet, a Java Web Start application or some other Java program. This tutorial is far from complete, but it will be updated on a regular basis.
- Part I: General Use of iText
- Part II: Using High Level Objects
- Part III: Fonts
- Part IV: Direct Content
- Part V: Interactive Features (AcroForms)
- Part VI: the iText Toolbox explained
- Part VII: RTF
- Part VIII: HTML
- Part IX: XML
- Part X: Under the hood
Part I: General Use of iText
Hello WorldHow-to generate a PDF document with iText in 5 easy steps. | |
Sections | Examples DefaultPageSize Generates a PDF document with the default page size and some other predefined standard pagesizes Output: LandscapePortrait Generates a PDF document with the first page in Lanscape; the second page in Portrait Output: HelloEncrypted Again a PDF with the text 'Hello World', but this time the document is encrypted. To read it, you need to know the userpassword: 'Hello' Output: ANT script (all examples): |
iText in a Web ApplicationHow-to use iText in Web Applications. | |
Sections | Examples HelloWorldServlet Generates a simple 'Hello World' file from a servlet (PDF, HTML or RTF) Extra jars needed:
Servlets/JSP: OutSimplePdf Generates a simple PDF file from a servlet. The file is buffered and served with the extension .pdf Extra jars needed:
Servlets/JSP: UserAgent.jsp Looks at the user-agent: if MSIE on Windows, embed the PDF; if another browser, redirect to the servlet Servlets/JSP: ProgressServlet Shows how to avoid receiving a timeout in your browser if generating the PDF takes a really long time. Extra jars needed:
Servlets/JSP: SilentPrintServlet Explains how to print silently via Servlet/Browser. Extra jars needed:
Servlets/JSP: ANT script (all examples): |
Manipulating existing PDF documentsHow-to copy/manipulate existing PDF documents. | |
Sections | Examples Concatenate Concatenates existing PDF files Argument(s):
Input: Output: ANT script (all examples): |
Frequently Asked QuestionsThis is a basic technical reference that answers some frequently asked questions. | |
Sections | Examples ANT script (all examples): |
Part II: Using High Level Objects
Basic Text ObjectsSome basic text objects that are used in iText. | |
Sections | Examples SymbolSubstitution Demonstrates how special characters are substituted by Symbols with Phrase.getInstance Output: FontSelection Selects the appropriate fonts that contain the glyphs needed to render text correctly Output: ANT script (all examples): |
The Chunk ObjectDescribes the functionality of the Chunk object. | |
Sections | Examples ANT script (all examples): |
Anchors, Actions and AnnotationsDeals with all the RemoteGoto, LocalGoto, Action, Annotation,... functionality | |
Sections | Examples OpenApplication Creates a document with a link to open an external application. Argument(s):
Output: ANT script (all examples): |
Viewerpreferences, Pagelabels, Optional Content and BookmarksDeals with all the PDF Viewerpreferences, Bookmarks, Outlines, Destinations,... functionality | |
Sections | Examples ViewerPreferences Creates five versions of the same document, but with different viewerpreferences Output: OutlineActions Creates a document with external destinations or actions that can be called from Bookmarks Output: ANT script (all examples): |
ImagesDeals with all types of images that are supported by iText | |
Sections | Examples ImageSequence Adds images to a document, once respecting the order in which they were added, once in the default order. Input: Output: DvdCover Make a DVD Cover. Argument(s):
Input: Output: ANT script (all examples): |
Selected examples: EPS, TIFF, BarcodesSelected examples: Embedding PostScript, importing TIFF files, Barcodes | |
Sections | Examples OddEven Combines 2 tiffs, one with odd, another with even pages into 1 combined PDF Argument(s):
Input: Output: ANT script (all examples): |
TablesHow to organize text and data in tables with iText | |
Sections | Examples SplitRows Add a table to a PDF with document.add() and if the cell doesn't fit, the row is split in two parts Output: ANT script (all examples): |
PdfPTableSome extra PdfPTable functionality | |
Sections | Examples FragmentTable Break one large Table up into different smaller tables with the same header Argument(s):
Output: ANT script (all examples): |
Alternatives for PdfPTableSome alternative ways to create a Table | |
Sections | Examples ANT script (all examples): |
ColumnTextHow to organize text and data in columns with iText | |
Sections | Examples ANT script (all examples): |
Part III: Fonts
The Font objectsDescribes the different Font objects in iText. | |
Sections | Examples ANT script (all examples): |
Font characteristicsChanging the style of a Font. | |
Sections | Examples ANT script (all examples): |
Getting fontsOverview of the different types of fonts supported by iText. | |
Sections | Examples UsingFontFactory Sums up the Fonts that are available in some standard font directories on your system Output: OpenTypeFont Using an Open Type Font with Compact Font Format (CFF) data only (no true type outlines) Input: Output: ANT script (all examples): |
Part IV: Direct Content
Direct ContentAdd content directly to the PDF file using the PdfContentByte class. | |
Sections | Examples ANT script (all examples): |
Coordinate SystemsCoordinate Systems - changing the Current Transformation Matrix (CTM) | |
Sections | Examples XandYcoordinates Puts some marks at specific X and Y coordinates; connects the marks with a line and puts some text next to the marks Output: ANT script (all examples): |
Graphics StateAdd graphics directly to the PDF file using the PdfContentByte class. | |
Sections | Examples ANT script (all examples): |
ColorsColors, Transparency, Spotcolors, Patterns and Shading. | |
Sections | Examples ANT script (all examples): |
TextAdd text content directly to the PDF file using the PdfContentByte class. | |
Sections | Examples ANT script (all examples): |
Page EventsAdd content directly to the PDF file using the PdfContentByte class. | |
Sections | Examples PageNumbersWatermark Making a document with a header containing 'page x of y' and with a watermark on every page. Input: Output: ANT script (all examples): |
Optional ContentAdd optional content to a PDF file. | |
Sections | Examples ANT script (all examples): |
Graphics2DIf you don't want to read all the chapters on PDF syntax, just use the JAVA API | |
Sections | Examples ANT script (all examples): |
Part V: Interactive Features (AcroForms)
Under Construction
Go to top of the pagePart VI: the iText Toolbox explained
Under Construction
Go to top of the pagePart VII: RTF
Rich Text FormatHow-to generate RTF documents using iText. | |
Sections | Examples ANT script (all examples): |
Part VIII: HTML
Generating HTML with iTextHow-to generate a HTML documents with iText | |
Sections | Examples ANT script (all examples): |
Part IX: XML
Under Construction
Go to top of the pagePart X: Under the hood
Under Construction
Go to top of the page