iText Core/Community

repository·develop·Indexed 25 days ago

https://github.com/itext/itext-java

A high-performance Java library for the creation, manipulation, and maintenance of PDF documents. It provides a layout engine for transforming abstract elements into PDF drawing operations and supports digital signatures, forms, and specialized standards like PDF/A and PDF/UA. Features include Brotli compression (version 9.5.0+), GraalVM native image support (version 8.0.3+), and capabilities for barcode generation, SVG support, and FIPS-compliant cryptography.

Tokens
6.6K
Snippets
19
Records
42
Agent score
78%

What's inside itext-java

  1. Overview of iText Core/Community features

    develop

    iText Core/Community is a high-performance Java library for creating, adapting, inspecting, and maintaining PDF documents.

    Core Library Capabilities:

    • PDF creation using a layout engine
    • PDF manipulation (e.g., merging PDFs, adding content)
    • PDF digital signing
    • PDF form creation and manipulation
    • PDF/A and PDF/UA support
    • FIPS-compliant cryptography
    • Barcode generation
    • SVG support

    Available Addons:

    • XML/HTML & CSS to PDF conversion
    • OCR on images and PDF documents
    • Redaction of sensitive information
    • International character set support (Arabic, Chinese, Hebrew, Thai, etc.)
    • PDF optimization for file size and performance
    • XFA document flattening
    • PDF debugging tools
  2. Understand the GNU Affero General Public License (AGPL) v3.0

    develop

    The iText project is licensed under the GNU Affero General Public License (AGPL) version 3.0. This is a strong copyleft license designed to ensure that the software remains free and open, even when used over a network.

    Key implications for users:

    • Network Interaction: Unlike the standard GPL, the AGPL requires that if you modify the program and run it on a computer network for users to interact with remotely, you must provide them with the opportunity to receive the Corresponding Source of your version via a network server at no charge.
    • Copyleft: If you convey a work based on the Program, you must license the entire work, as a whole, under this License.
    • No Warranty: The program is provided "AS IS" without warranty of any kind.
    • Patent License: Contributors grant a non-exclusive, worldwide, royalty-free patent license under their essential patent claims to make, use, sell, and propagate the contents of their contributor version.
  3. Support complex writing systems with PDF Calligraph

    develop
    iText provides support for complex writing systems (such as Arabic) through PDF Calligraph. This allows for correct rendering of typography, including features like Arabic word spacing.
  4. Provisions for User Products and Installation Information

    develop

    If you convey an object code work specifically for use in a User Product (a consumer product or something designed for a dwelling) and the right of possession is transferred to the recipient in perpetuity or for a fixed term, you must also provide Installation Information.

    Installation Information includes any methods, procedures, or authorization keys required to install and execute modified versions of the covered work in that User Product from its Corresponding Source. This information must ensure that the continued functioning of the modified object code is not prevented or interfered with solely because of the modification.

  5. Understand iText licensing (AGPL vs Commercial)

    develop

    iText is dual-licensed under AGPL and Commercial terms:

    • AGPL (Affero General Public License): A free/open-source copyleft license. If you use iText in a derivative work, that work must also be licensed under the AGPL.
    • Commercial License: Available for users whose software or services cannot comply with the AGPL terms. This license exempts you from the copyleft obligations.

    For more information on choosing a license, contact iText Sales.

  6. How the iText Layout module works

    develop

    The Layout module transforms abstract model elements (like Paragraph, Table, or List) into low-level PDF drawing operations on actual pages.

    It operates using a two-step rendering process:

    1. Layout(): Calculates the exact position and area (using LayoutBBox and OccupiedArea) that an element takes up on the canvas. This step is recursive (depth-first) and handles element splitting across pages by creating a split renderer (for the part that fits) and an overflow renderer (for the part that moves to the next page).
    2. Draw(): Generates the actual PDF syntax (drawing instructions) based on the results of the layout step. This step modifies the PdfDocument.

    Elements are organized in a tree structure. When you add elements to a Document or Canvas, iText converts this model tree into a renderer tree using IElement#createRendererSubTree before performing the layout.

    Div container = new Div();
    Paragraph paragraph = new Paragraph("New paragraph.");
    container.add(paragraph);
  7. Compare Document, Canvas, PdfDocument, and PdfCanvas

    develop

    When working with the layout module, it is critical to distinguish between high-level layout abstractions and low-level PDF structures:

    Abstraction LevelClassPurpose
    High-Level (Layout)DocumentThe main entry point for adding elements; uses DocumentRenderer to handle page creation and continuous placement.
    High-Level (Layout)CanvasWrites layout objects to a single arbitrary content stream (e.g., PdfFormXObject); content that doesn't fit the area is not shown.
    Low-Level (PDF)PdfDocumentWorks directly with PDF pages and internal objects like arrays and dictionaries.
    Low-Level (PDF)PdfCanvasPerforms low-level drawing operations (e.g., drawing a character at a specific coordinate).
  8. Understand Property Containers and Layout Objects

    develop

    iText uses the IPropertyContainer interface to manage element data via a map-based property system rather than standard class fields. This allows for memory efficiency and a simple inheritance mechanism.

    • IPropertyContainer: Defines methods to set, get, and delete properties using generic types and property numbers (defined in com.itextpdf.layout.property.Property).
    • Inheritance: If a property is not found in the current element's map, IPropertyContainer#getProperty searches parent maps recursively. Some properties are marked as inheritable in Property#INHERITED_PROPERTIES.
    • IElement: Sub-interface implemented by model objects like Text, Paragraph, and Table.
    • IRenderer: Sub-interface implemented by rendering logic like TextRenderer or TableRenderer.

    Best Practice: If you need to override model element properties during the layout process, set them on the renderer instead of the model element to avoid polluting the model structure.