IronPdf is a library developed and maintained by Iron Software that helps Software Engineers to create, edit and extract PDF content in projects in Java.
- 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*
To define IronPDF as a dependency, please add the following excerpt to your pom.xml:
<dependencies>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>20xx.xx.xxxx</version>
</dependency>
</dependencies>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 sample HTML to PDF example to get started:
PdfDocument pdfDocument = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");
pdfDocument.saveAs(Paths.get("html_saved.pdf"));This is another example which demonstrates URL to PDF:
PdfDocument pdfDocument = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");
pdfDocument.saveAs(Paths.get("url_saved.pdf"));Note: Please note that all settings, logging, and licensing operations must be executed before any IronPDF methods are called.
com.ironsoftware.ironpdf.License.setLicenseKey("YOUR-LICENSE-KEY");IronPdf Java uses the slf4j logger. To enable logging use:
com.ironsoftware.ironpdf.Settings.setDebug(true);To specify the IronPdfEngine log path add:
com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log"));Not familiar with slf4j? Just add this to your pom.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.17</version>
</dependency>IronPDF for Java is based on IronPDF for .NET, it will generally be about 1 version behind.
IronPDF for Java uses gRPC to communicate with the IronPdfEngine, which consumes IronPDF for .NET
IronPdfEngine is the core of IronPdf. To use IronPdf for Java IronPdfEngine binaries is required.
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.
By default IronPdf for Java will download IronPdfEngine binaries on the first run (or when it cannot find the binaries).
Note: For macOS,
IronPdfEnginebinaries that download on the first run might not work in your system (Gatekeeper on macOS). Please useIronPdfEngineas a maven dependency instead (next section)
For most applications the engine lifecycle is fully automatic and you never need
to manage it. Long-running services, however, may need to recover when the engine
is interrupted by something outside IronPDF's control, e.g. a remote IronPdfEngine
host restart, an OS kill, or a native crash. After such an event the cached
connection becomes stale and further calls can hang or fail.
com.ironsoftware.ironpdf.IronPdfEngineManager provides a small, thread-safe API
for this:
| Method | Description |
|---|---|
IronPdfEngineManager.isEngineActive() |
Health check. Returns true only if the engine is connected and answers a handshake. Never starts the engine. Non-blocking against a running engine (a single 5s-deadline handshake); if a connect/restart is in progress on another thread, it waits for that to finish. |
IronPdfEngineManager.startEngine() |
Starts/connects the engine (same as the implicit first-call behaviour). No-op if already healthy. |
IronPdfEngineManager.stopEngine() |
Stops the local subprocess (or closes the channel in remote modes). |
IronPdfEngineManager.restartEngine() |
Stops then re-establishes a fresh connection. The recommended recovery action. It resets the stale state that a plain call would not. |
A typical watchdog pattern:
import com.ironsoftware.ironpdf.IronPdfEngineManager;
import com.ironsoftware.ironpdf.PdfDocument;
// Recover automatically if the engine was interrupted (host restart, crash, kill).
if (!IronPdfEngineManager.isEngineActive()) {
IronPdfEngineManager.restartEngine();
}
PdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>Hello World</h1>");
pdf.saveAs("output.pdf");Note:
isEngineActive()reports the connection IronPDF holds, regardless of connection mode (subprocess or remote). It does not depend on inspecting OS processes, so it works the same way for local and remote engines.
Note:
stopEngine()andrestartEngine()are not supported inCUSTOMconnection mode (withCustomGrpcConnection) and throwUnsupportedOperationException. In that mode the gRPC channel is supplied by you and IronPDF cannot rebuild it once shut down, so you are responsible for its lifecycle.isEngineActive()andstartEngine()work in all modes.
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:
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-windows-x64</artifactId>
<version>20xx.xx.xxxx</version>
</dependency><dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-windows-x86</artifactId>
<version>20xx.xx.xxxx</version>
</dependency><dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>20xx.xx.xxxx</version>
</dependency><dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-macos-x64</artifactId>
<version>20xx.xx.xxxx</version>
</dependency><dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-macos-arm64</artifactId>
<version>20xx.xx.xxxx</version>
</dependency>IronPdf for Java is free to use and test with an IronPDF watermark applied. To remove the watermark apply for a license or trial license..
For our full list of code examples, tutorials, licensing information, and documentation visit: https://ironpdf.com/java
For more support and inquiries, please email us at: support@ironsoftware.com