iText Tutorial / Example

iText Tutorial describes about creating pdf documents using Java and iText.

Creating PDF files in enterprise web applications is quite common in these days.

iText is a free and open-source tool for manipulating and creating PDF files in Java.

It had been written by Paulo Soares, Bruno Lowagie and others. It allows developers looking to boost web applications with dynamic PDF content  manipulation.

You can see the below example, which is demonstrating How to Use IText in java for generating PDF

Required Libraries

You need to download

  1. JDK 6
  2. itext-5.1.2.jar in classpath

Create PDF With iText

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class CreatePDFWithItext{

 
public static void main(String[] args) {
   
try {
     
OutputStream file = new FileOutputStream(new File("C:\\example.pdf"));
      Document document =
new Document();
      PdfWriter.getInstance
(document, file);
      document.open
();
      document.add
(new Paragraph("Hello World"));
      document.add
(new Paragraph("http://www.javatips.net/"));
      document.add
(new Paragraph(new Date().toString()));
      document.close
();
      file.close
();
   
} catch (Exception e) {
     
e.printStackTrace();
   
}
  }
}





Your email address will not be published. Required fields are marked *