Free Java Apache PDFBox Templates (Permissive Apache-2.0, Zero AGPL)

Apache-2.0 pure-Java PDF canvas and object manipulator for Spring Boot, Quarkus, and Kotlin — avoids AGPL licensing fees and generates 22 stress-test pages in just 48 ms on a warm JVM (2.8 ms / 1.8 KB single-page, 117.6 MB RAM).

Install: implementation "org.apache.pdfbox:pdfbox:3.0.3" | Runtime: Java (Java 17/21) | Version: 3.0.3 | Popularity: 3.8M/mo installs

Works with: Spring Boot, Quarkus, Micronaut, Kotlin / JVM, AWS Lambda Java

How Apache PDFBox (Java) Templates Work in CodePDF

Compiles visual components into a self-contained Java class using PDDocument, PDPage, and PDPageContentStream (supporting both PDFBox 3.0 PDType1Font(FontName.*) and legacy 2.0 APIs).

  • 100% permissive Apache-2.0 library + MIT-owned generated Java code — zero commercial licensing fees
  • Handles bottom-left coordinate math, multiline text wrapping, and dynamic List<Map> table pagination
  • Supports both Apache PDFBox 3.0.x and 2.0.x in the version picker

Quick Start: Generate PDFs with PDFBox

Install Apache PDFBox (Java) (Java 17/21), then run the code CodePDF exports for any template:

<!-- Maven: add to pom.xml --> <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>3.0.3</version> </dependency>

  1. Add the PDFBox dependency to your Maven or Gradle project (see above).
  2. Save the generated file as DocumentGenerator.java in your project.
  3. Compile: javac -cp pdfbox-3.0.3.jar DocumentGenerator.java
  4. Run: java -cp .:pdfbox-3.0.3.jar DocumentGenerator
  5. The PDF will be saved to document.pdf in the working directory.

Example PDFBox Output (Standard B2B Commercial Invoice)

Compiled directly from the Standard B2B Commercial Invoice template (Java 17/21):

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts;

// This code is generated using codepdf.dev

public class DocumentGenerator {

    private static PDFont stdFont(Map<Standard14Fonts.FontName, PDFont> cache, Standard14Fonts.FontName name) {
        return cache.computeIfAbsent(name, n -> new PDType1Font(n));
    }

    private static String safePdfText(PDFont font, String s) {
        if (s == null || s.isEmpty()) return "";
        String cleaned = s.replace("\t", "    ").replace("\r", "");
        StringBuilder sb = new StringBuilder(cleaned.length());
        for (int i = 0; i < cleaned.length(); i++) {
            char ch = cleaned.charAt(i);
// … (1105 more lines in full generated file)

Custom Fonts in PDFBox

Generated draw calls default to Standard 14 fonts; bind PDType0Font.load(document, new File(...)) to contentStream.setFont() for custom TrueType (.ttf) Unicode subsetting.

  1. Place TrueType .ttf files in ./fonts/ accessible to the JVM.
  2. Call PDType0Font.load(document, new File("{{FONT_LOCAL_PATH}}")) once per weight.
  3. Pass the loaded PDFont object to contentStream.setFont(customFont, size).

Official documentation: PDFBox docs

PDFBox Benchmark Results

Measured on CodePDF’s 26-component, 22-page All-Components Dynamic Multi-Page Flow Stress Test (same document across all 22 libraries).

Apache PDFBox (Java) stress-test results and rank out of 22 PDF libraries
MetricPDFBoxRank (of 22)
Wall-clock time48 ms6th fastest
CPU time0.98 s14th lowest
Peak RAM117.6 MB12th lowest
PDF file size148.2 KB8th smallest
Engine type
Low-Level / Object Editor
Under the hood
Pure-Java Apache PDFBox 3.0 PDPageContentStream canvas & PDF parser/editor
Runs in
JVM (Spring Boot, Quarkus, Micronaut, Kotlin)
Verdict
Permissive Apache-2.0 Java engine that creates & edits PDFs in just 48 ms across 22 pages (2.8 ms single-page, 117.6 MB JVM RAM).

Under the Hood & Benchmark Highlights

  • Apache-2.0 licensed pure-Java engine — avoids iText’s AGPL commercial fees while supporting both creating new PDFs and editing/merging existing ones.
  • Produces compact vector PDFs (3.1 KB single-page; 124.8 KB across 11 stress-test pages), though Maven + JVM startup drove peak RSS to 395.4 MB and 3.40s wall-clock in our one-shot CLI run (long-lived Spring Boot JVMs amortize startup).
  • Mind the breaking API change between PDFBox 2.x and 3.x (Standard14Fonts.FontName).

Good to Know (PDFBox Caveats)

  • Breaking changes between 2.x and 3.x: PDFBox 3.0 replaced static PDType1Font constants with new PDType1Font(Standard14Fonts.FontName.*) and Loader.loadPDF() — match the version picker to your Maven/Gradle dependency.
  • Unicode requires PDType0Font.load(): Built-in Standard-14 fonts throw IllegalArgumentException on unsupported Unicode characters (including some punctuation/currency glyphs); embed a .ttf font for full UTF-8.
  • Bottom-left coordinates & cold JVM startup: Uses explicit PDPageContentStream drawing from bottom-left points; JVM cold starts add latency in short-lived serverless functions.

Popular PDFBox PDF Templates

All 100 CodePDF templates export to Apache PDFBox (Java). Browse them by category: Career (5) · Business (6) · Education (7) · Marketing (6) · Human Resources (8) · Finance (7) · Legal (8) · Healthcare (10) · Logistics (6) · Real Estate (6) · Hospitality (4) · Operations (5) · Technology (5) · Banking (9) · Non-Profit (4) · Personal (3) · Compliance & Enterprise (1), or see the full template gallery.

PDFBox Template FAQs

Is Apache PDFBox free for commercial closed-source Java applications?

Yes! Apache PDFBox is Apache-2.0 licensed, and all Java code generated by CodePDF is 100% yours under MIT — making it a popular free alternative to AGPL-licensed libraries.

Does CodePDF support both PDFBox 3.0 and PDFBox 2.0?

Yes — select v3.0.3 (new Standard14Fonts.FontName API) or v2.0.31 in CodePDF's code generator modal.

Can I use exported Java PDFBox classes in Kotlin or Spring Boot?

Yes — call the generated method with a ByteArrayOutputStream and return ResponseEntity<byte[]> from any Spring Boot or Kotlin controller.

Compare PDFBox with Other PDF Libraries

PDFBox is the only Java engine CodePDF targets. See the full 22-library benchmark rankings · Compare all supported PDF libraries