iText 7 for Java: Complete Guide to Creating and Editing PDF
\n\niText 7 is a powerful open-source (AGPL) library for Java, designed for programmatic creation, manipulation, and rendering of PDF documents. It is the successor to the popular iText 5 library and offers a completely redesigned, modular architecture focused on performance, flexibility, and ease of use. iText 7 allows developers to solve a wide range of tasks: from generating simple invoices and reports to creating complex, legally significant documents with digital signatures, forms, and metadata.
\n\nWhy is iText 7 needed? In the modern world, PDF is a universal format for document exchange, guaranteeing consistent display on any device. Manual creation of PDF files is time-consuming and inefficient, especially when working with large volumes of data. iText 7 automates this process, giving Java developers full control over every aspect of the document: from adding text and images to creating interactive forms and managing access rights. It is indispensable in document management systems, e-commerce, banking, and any other applications requiring PDF generation or processing.
\n\nThe library supports all the latest PDF specifications, including PDF 2.0. It also provides additional modules (add-ons) for working with HTML conversion (pdfHTML), optical character recognition (pdfOCR), SVG creation (pdfSVG), and image processing (pdfImage). It is important to note that iText 7 is distributed under a dual license: AGPL (requires open-sourcing your application) and commercial (for proprietary use).
\n\nInstallation
\nTo install iText 7 in your Java project, use the Maven or Gradle build system. Below is the exact command for adding dependencies to the pom.xml file (Maven).
<!-- pom.xml -->\n<dependencies>\n <!-- Main iText 7 module -->\n <dependency>\n <groupId>com.itextpdf</groupId>\n <artifactId>itext7-core</artifactId>\n <version>8.0.4</version> <!-- Check the latest version on Maven Central -->\n <type>pom</type>\n </dependency>\n</dependencies>\n\nFor Gradle (build.gradle):
\nimplementation 'com.itextpdf:itext7-core:8.0.4'\n\nIf you only need specific modules (e.g., kernel, layout, io), you can add them individually:
<dependency>\n <groupId>com.itextpdf</groupId>\n <artifactId>kernel</artifactId>\n <version>8.0.4</version>\n</dependency>\n<dependency>\n <groupId>com.itextpdf</groupId>\n <artifactId>layout</artifactId>\n <version>8.0.4</version>\n</dependency>\n\nQuick Start: Minimal Working Example
\nThe following code creates a simple PDF document with the text "Hello, World!" and saves it to the file HelloWorld.pdf.
import com.itextpdf.kernel.pdf.PdfDocument;\nimport com.itextpdf.kernel.pdf.PdfWriter;\nimport com.itextpdf.layout.Document;\nimport com.itextpdf.layout.element.Paragraph;\n\nimport java.io.FileNotFoundException;\n\npublic class HelloWorld {\n public static void main(String[] args) throws FileNotFoundException {\n // 1. Create a PdfWriter that will write data to the file\n PdfWriter writer = new PdfWriter("HelloWorld.pdf");\n \n // 2. Create a PdfDocument — an object representing the PDF document itself\n PdfDocument pdf = new PdfDocument(writer);\n \n // 3. Create a Document — a high-level object for adding Also in library
multierr for Go: A Complete Guide with Examples
Generating PDF Reports in PHP: Library Overview and Code Examples
Event Bus and Observer Pattern in Java: Implementing a Loosely Coupled Architecture
Superstruct for TypeScript: Complete Guide with Examples