IronPDF for Java - Create, Edit, and Read PDFs in Java Applications

About IronPDF for Java

IronPDF for Java is a library developed and maintained by Iron Software that helps Software Engineers to create, edit and extract PDF content in Java 8+, Kotlin, and Scala projects.

IronPDF for Java builds upon the success and popularity of IronPDF for .NET.

IronPDF for Java uses gRPC to communicate with the IronPdfEngine.

IronPDF excels at

  • Generating PDFs from: HTML, URL, JavaScript, CSS and many image formats
  • Adding headers/footers, signatures, attachments, and passwords and security
  • Performance optimization: Full Multithreading and Async support
  • And many more! Visit our website to see all our code examples and a full list of our 50+ features*

Using IronPDF for Java

Define IronPDF as a Java Dependency

pom.xml Dependency

To define IronPDF as a dependency, please add the following to your pom.xml:

<dependencies>

<!--Adds IronPDF Java. Use the latest version in the version tag.-->
    <dependency>
        <groupId>com.ironsoftware</groupId>
        <artifactId>ironpdf</artifactId>
        <version>20xx.xx.xxxx</version>
    </dependency>

<!--Adds the slf4j logger which IronPDF Java uses.-->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>2.0.3</version>
    </dependency>

</dependencies>
XML

Download jar file

Optionally download the .jar manually.

First Build and Run

IronPdfEngine binaries will automatically be downloaded when running the project for the first time. The IronPdfEngine process will start when you call any IronPdf function for the first time, and stop when your application is closed, or when it enters an idle stage.

Install IronPDF Engine as a Maven Dependency

By adding IronPdfEngine as a Maven dependency, the binaries will be downloaded during the loading of dependencies:

  • This approach will avoid a lengthy startup process, as the IronPdfEngine binaries will already be downloaded.
  • Moreover, it will be beneficial for deployment setups that do not allow downloading from external sources.

Simply add one or multiple of the following code snippets to your pom.xml file if you are working on a multiplatform app:

For windows x64

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-windows-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

For windows x86

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-windows-x86</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

For Linux x64

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-linux-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

For macOS x64 (Intel)

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-macos-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

For macOS Arm (Apple Silicon)

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-macos-arm64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

Start writing Java code

Once the dependence is defined, you can get started by adding the import com.ironsoftware.ironpdf.* statement to the top of your Java code. Here is a simple sample HTML to PDF example to get started:

// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Render the HTML as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");

// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("html_saved.pdf"));
JAVA

This is another simple example which demonstrates URL to PDF:

// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Render the URL page as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");

// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("url_saved.pdf"));

PdfDocument pdfDocument = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");
JAVA

Full Main.java Example

package org.example;  

// Import statement for IronPDF Java  
import com.ironsoftware.ironpdf.*;  
import java.io.IOException;  
import java.nio.file.Paths;  

public class Main {  

    public static void main(String [] args) throws IOException {
        // Apply your license key
        License.setLicenseKey("YOUR-LICENSE-KEY");  

        // Set a log path  
        Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));  

        // Render the HTML as a PDF. Stored in myPdf as type PdfDocument  
        PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");  

        // Save the PdfDocument to a file  
        myPdf.saveAs(Paths.get("html_saved.pdf"));

    }  

}
JAVA

Further Settings Information

Note: Please note that all settings, logging, and licensing operations must be executed before any IronPDF methods are called.

Applying License Key

To apply your license key, add the following to the top of your method:

com.ironsoftware.ironpdf.License.setLicenseKey("YOUR-LICENSE-KEY");
JAVA

Logging

IronPDF Java uses the slf4j logger. To enable logging use:

com.ironsoftware.ironpdf.Settings.setDebug(true);
JAVA

To specify the IronPdfEngine log path add:

com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log"));
JAVA

Licensing & Support Available

Purchase a license to use IronPdf in live projects. 30 day Trial licenses are also available here.

For our full list of code examples, tutorials, licensing information, and documentation visit: IronPDF for Java.

For more support and inquiries, please ask our team.