Convert Figma logo to code with AI

itext logoitext-java

iText for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText can be a boon to nearly every workflow.

1,969
444
1,969
44

Top Related Projects

2,609

Mirror of Apache PDFBox

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

3,494

OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.

JODConverter automates document conversions using LibreOffice or Apache OpenOffice.

Quick Overview

iText is a powerful PDF library for Java, allowing developers to create, manipulate, and process PDF documents programmatically. It offers a wide range of features for working with PDFs, including document generation, form filling, digital signatures, and more.

Pros

  • Comprehensive PDF manipulation capabilities
  • Actively maintained with regular updates
  • Extensive documentation and community support
  • High performance and scalability for large-scale PDF operations

Cons

  • Complex API for some advanced features
  • Commercial license required for certain use cases
  • Steep learning curve for beginners
  • Large library size, which may impact application size

Code Examples

Creating a simple PDF document:

PdfWriter writer = new PdfWriter(dest);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
document.add(new Paragraph("Hello World!"));
document.close();

Adding a table to a PDF:

Table table = new Table(UnitValue.createPercentArray(3)).useAllAvailableWidth();
table.addCell("Cell 1");
table.addCell("Cell 2");
table.addCell("Cell 3");
document.add(table);

Filling a PDF form:

PdfDocument pdf = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
form.getField("name").setValue("John Doe");
form.getField("address").setValue("123 Main St");
pdf.close();

Getting Started

To use iText in your Java project, add the following dependency to your Maven pom.xml:

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext7-core</artifactId>
    <version>7.2.3</version>
    <type>pom</type>
</dependency>

For Gradle, add this to your build.gradle:

implementation 'com.itextpdf:itext7-core:7.2.3'

Then, you can start using iText in your Java code:

import com.itextpdf.kernel.pdf.*;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

public class HelloWorld {
    public static void main(String[] args) throws Exception {
        PdfWriter writer = new PdfWriter("hello_world.pdf");
        PdfDocument pdf = new PdfDocument(writer);
        Document document = new Document(pdf);
        document.add(new Paragraph("Hello World!"));
        document.close();
    }
}

This example creates a simple PDF document with the text "Hello World!".

Competitor Comparisons

2,609

Mirror of Apache PDFBox

Pros of PDFBox

  • Open-source and free to use under Apache License 2.0
  • Extensive documentation and community support
  • Lighter weight and easier to integrate into existing projects

Cons of PDFBox

  • Generally slower performance, especially for large PDF files
  • Less feature-rich compared to iText, particularly for advanced PDF manipulation

Code Comparison

iText:

PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
document.add(new Paragraph("Hello World!"));
document.close();

PDFBox:

PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.showText("Hello World!");
contentStream.endText();
contentStream.close();
document.save(dest);
document.close();

The code comparison shows that PDFBox requires more lines of code to achieve the same basic task of creating a PDF with text. iText provides a more concise API for simple operations, while PDFBox offers more granular control over the PDF creation process.

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

Pros of OpenHTMLtoPDF

  • Open-source and free to use, with a more permissive license
  • Better support for HTML and CSS rendering, including flexbox and grid layouts
  • More active community development and frequent updates

Cons of OpenHTMLtoPDF

  • Less mature and potentially less stable compared to iText
  • Smaller ecosystem and fewer third-party integrations
  • May have performance limitations with very large documents

Code Comparison

OpenHTMLtoPDF:

PdfRendererBuilder builder = new PdfRendererBuilder();
builder.withUri("input.html");
builder.toStream(outputStream);
builder.run();

iText:

HtmlConverter.convertToPdf(new File("input.html"),
                           new File("output.pdf"),
                           new ConverterProperties());

Both libraries offer relatively simple APIs for converting HTML to PDF. OpenHTMLtoPDF provides more granular control over the conversion process, while iText's approach is more straightforward for basic use cases.

OpenHTMLtoPDF is a good choice for projects requiring accurate HTML/CSS rendering and those preferring open-source solutions. iText may be better suited for enterprise applications or scenarios demanding high performance and extensive documentation.

3,494

OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.

Pros of OpenPDF

  • Open-source and free to use, with a more permissive license (LGPL/MPL)
  • Maintained by a community, potentially leading to faster bug fixes and feature additions
  • Forked from an earlier version of iText, maintaining compatibility with many existing projects

Cons of OpenPDF

  • Smaller user base and community compared to iText
  • May lack some of the more advanced features found in recent iText versions
  • Potentially slower development cycle for major new features

Code Comparison

OpenPDF:

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
document.open();
document.add(new Paragraph("Hello, OpenPDF!"));
document.close();

iText:

PdfWriter writer = new PdfWriter("output.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
document.add(new Paragraph("Hello, iText!"));
document.close();

The code snippets show that both libraries have similar basic usage patterns, but iText has a slightly different object hierarchy and initialization process. OpenPDF's API is more similar to older versions of iText, which may be beneficial for projects migrating from earlier iText versions.

JODConverter automates document conversions using LibreOffice or Apache OpenOffice.

Pros of JODConverter

  • Supports a wide range of document formats, including Office documents and PDFs
  • Utilizes LibreOffice/OpenOffice for high-quality conversions
  • Offers both a Java library and a REST microservice

Cons of JODConverter

  • Requires LibreOffice/OpenOffice installation, which can be resource-intensive
  • May have slower conversion speeds compared to iText for PDF-specific operations
  • Limited to document conversion tasks, while iText offers more PDF manipulation features

Code Comparison

JODConverter:

JodConverter.convert(inputFile).to(outputFile).execute();

iText:

PdfDocument pdf = new PdfDocument(new PdfReader(inputFile), new PdfWriter(outputFile));
PdfMerger merger = new PdfMerger(pdf);
merger.merge(pdf, 1, pdf.getNumberOfPages());
pdf.close();

JODConverter focuses on simple document conversion with a single method call, while iText provides more granular control over PDF operations. iText is better suited for complex PDF manipulations, whereas JODConverter excels in converting between various document formats. The choice between the two depends on the specific requirements of the project, with JODConverter being more versatile for general document conversions and iText being more powerful for PDF-specific tasks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Logo iText

Maven Central AGPL License GitHub all releases GitHub commit activity (branch)

iText Core/Community is a high-performance, battle-tested library that allows you to create, adapt, inspect and maintain PDF documents, allowing you to add PDF functionality to your software projects with ease. It is also available for .NET (C#).

The key features of iText Core/Community are:

  • Core library:
    • PDF creation with the use of our layout engine
    • PDF manipulation, e.g. merging multiple PDFs into one, adding new content, ...
    • PDF digital signing
    • PDF form creation and manipulation
    • Working with PDF/A documents
    • Working with PDF/UA documents
    • FIPS-compliant cryptography
    • Barcode generation
    • SVG support
  • Addons:
    • Converting XML/HTML & CSS to PDF repo, info
    • Redacting sensitive information in PDF documents repo, info
    • Support for international character sets (e.g. Arabic, Chinese, Hebrew, Thai, ...) info
    • Optimize PDF documents for reduced file size, and increased performance info
    • Flattening XFA documents info
    • PDF debugging repo, info

Want to discover what's possible? Head over to our Demo Lab! It contains a collection of demo applications ready to use online!

Getting started

The easiest way to get started is to use Maven, just add the following entries to your pom.xml file:


<properties>
  <itext.version>REPLACE_WITH_DESIRED_ITEXT_VERSION</itext.version>
</properties>
<dependencies>
  <dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itext-core</artifactId>
    <version>${itext.version}</version>
    <type>pom</type>
  </dependency>
  <dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>bouncy-castle-adapter</artifactId>
    <version>${itext.version}</version>
  </dependency>
</dependencies>

For more advanced use cases, please refer to the Installation guidelines. You can also build iText Community from source.

Hello PDF!

The following example shows how easy it is to create a simple PDF document:

package com.itextpdf.hellopdf;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

import java.io.FileNotFoundException;

public class HelloPdfApp {

    public static void main(String[] args) throws FileNotFoundException {
      try (Document document = new Document(new PdfDocument(new PdfWriter("./hello-pdf.pdf")))) {
            document.add(new Paragraph("Hello PDF!"));
        }
    }
}

Examples

This is a small subset of examples to get you started. For more advanced examples, refer to our Knowledge Base or the following links: Examples repo, Signing examples.

Some of the output PDF files will be incorrectly displayed by the GitHub previewer, so be sure to download them to see the correct results.

DescriptionLink
Basic layout
Change text propertiesJava, PDF
Creating a simple tableJava, PDF
Add an image to a PDF documentJava, PDF
Create a listJava, PDF
Add a watermarkJava, PDF
Add links to navigate within a documentJava, PDF
Create a popup annotationJava, PDF
Change fontJava
Add form fieldsJava

General document settings
Change page size and marginJava, PDF
Write PDF to byte array instead of to diskJava
Change page rotationJava, PDF
Add header and footerJava, PDF
Merge documentsJava, PDF
Flatten annotationsJava

PDF/UA, PDF/A
Create PDF/UA documentJava, PDF
Create PDF/A-3 documentJava
Create PDF/A-4 documentJava
Create WTPDF documentJava

FIPS
Enable FIPSJava
FIPS SHA3 exampleJava

Convert HTML and CSS to PDFLink to repo
Convert simple HTML doc to PDFJava

Secure redaction of contentLink to repo
Redacting contentJava
Redact based on regexJava

Support complex writing systemsLink to docs
Add Arabic textJava, PDF

Optimizing PDFsLink to docs
Reduce size of PDFJava

XFA flatteningLink to docs
Flatten an XFA documentJava

RUPSLink to repo
Debug a PDFJava

FAQs, tutorials, etc.

Check out the iText Knowledge Base for the iText Jump-start tutorial and other tutorials, FAQs and more. For specific information and examples relating to digital signatures and iText, make sure to check the Digital Signatures Hub.

Many common questions have already been answered on Stack Overflow, so make sure to also check there.

Contributing

Many people have contributed to iText Core/Community over the years. If you've found a bug, a mistake in documentation, or have a hot new feature you want to implement, we welcome your contributions.

Small changes or fixes can be submitted as a Pull Request, while for major changes we request you contact us at community@apryse.com so we can better coordinate our efforts and prevent duplication of work.

Please read our Contribution Guidelines for details on code submissions, coding rules, and more.

Licensing

iText is dual licensed as AGPL/Commercial software.

AGPL is a free/open-source software license, however, this doesn't mean the software is gratis!

The AGPL is a copyleft license, which means that any derivative work must also be licensed under the same terms. If you’re using iText in software or a service which cannot comply with the AGPL terms, we have a commercial license available that exempts you from such obligations.

Contact Sales for more info.