Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Creating PDF with Java and iText - Tutorial

Lars Vogel

Version 0.5

11.10.2010

Revision History
Revision 0.128.06.2009Lars Vogel
Created
Revision 0.2 - 0.430.06.2009 - 11.10.2010Lars Vogel
bugfixes and enhancements

Java and PDF with iText

This article demonstrate how to create PDF files with Java and the iText library. In this tutorial iText version 5.0.x is used


Table of Contents

1. Overview
2. Installation
3. Create a PDF
4. Formatting your output
5. Read an existing pdf
6. Thank you
7. Questions and Discussion
8. Links and Literature
8.1. Source Code
8.2. iText Resources
8.3. vogella Resources

1. Overview

iText is a Java library originally created by Bruno Lowagie which allows to create PDF, read PDF and manipulate them. The following tutorial will show how to create PDF files with iText. This tutorial assumes that you have basis Java and Eclipse knowledge.

iText has a hierarchical structure. The smallest text unit is a "Chunk" which is a String with a pre-defined font. A "Phrase" combines several Chunks and allows to define line spacing. "Paragraph" is a subclass of "Phrase" and allows to define more layout attributes, e.g. margins. The class "Anchor" is a subclass of "Paragraph" and serves as the basis for hyperlinks in the generated PDF.