An Introduction To Apache iText

Posted By : Mohd Altaf | 29-Sep-2023

Java Java Virtual Machine

Loading...

iText PDF Java Introduction

Apache iText is an open-source Java Library that enables developing and converting PDF documents. The PDF is a Portable Document Format that helps present data in a manner that is independent of application software, hardware, and operating systems. Several libraries can create and manipulate documents through programs like Adobe PDF Library, Formatting Object Processor, Jasper Report, etc.

Features of iText

Following are the features of iText -

  • iText provides classes to generate interactive PDF documents. We can create maps and books using iText.
  • Using iText we can add bookmarks, watermarks, and page numbers.
  • Using iText we can split a PDF into multiple PDFs and also add additional pages.
  • Using iText, we can fill interactive forms in a PDF document.
  • Using iText, we can save PDF as an image file, such as PNG or JPEG.
  • iText library provides a Canvas class using which we can draw geometrical shapes.
  • Using iText, we can create PDF files from the Java programs. We can add images and fonts.

Add the following content to its pom.xml

<dependencies>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>kernel</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>io</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>layout</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>forms</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>pdfa</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>sign</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>barcodes</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>font-asian</artifactId>

<version>7.0.2</version>

</dependency>

<dependency>

<groupId>com.itextpdf</groupId>

<artifactId>hyph</artifactId>

<version>7.0.2</version>

</dependency>

</dependencies>

Program to create PDF document

package com.javapapers.java.itext;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import com.itextpdf.text.Document;

import com.itextpdf.text.DocumentException;

import com.itextpdf.text.Paragraph;

import com.itextpdf.text.pdf.PdfWriter;

public class PdfDocument {

public static void main(String[] args) {

Document document = new Document();

try {

PdfWriter.getInstance(document, new FileOutputStream(

"MyFirstDynamic.pdf"));

document.open();

document.add(new Paragraph(

"iText Core is a library that aids in creating, processing, and editing PDF documents"));

document.close();

} catch (DocumentException e) {

e.printStackTrace();

} catch (FileNotFoundException e) {

e.printStackTrace();

}

}

}

At Oodles, we provide full-scale ERP application development services to help our clients streamline their day-to-day business processes. Contact us at [email protected] for project-related queries.