IRONSOFTWAREHOME

IronPDF for Java - 在 Java 應用程式中建立、編輯及閱讀 PDF 檔案

Curtis Chau
Curtis Chau
Updated: 2026年4月22日

About IronPDF for Java

IronPDF for Java 是由 Iron Software 開發並維護的函式庫,可協助軟體工程師在 Java 8+、Kotlin 及 Scala 專案中建立、編輯及擷取 PDF 內容。

IronPDF for Java 延續了 IronPDF for .NET 的成功與廣受歡迎。

IronPDF for Java 採用 gRPC 與 IronPdfEngine 進行通訊。

IronPDF 擅長

  • 從以下來源生成 PDF:HTML、URL、JavaScript、CSS 及多種圖像格式
  • 新增頁首/頁尾、簽名、附件,以及密碼與安全性
  • 效能優化:全面支援多執行緒與非同步處理
  • 還有更多! 歡迎造訪我們的網站,查看所有程式碼範例以及 50 多種功能的完整清單

使用 IronPDF for Java

將 IronPDF 定義為 Java 依賴項

pom.xml 依賴項

若要將 IronPDF 定義為依賴項,請在您的 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

下載 jar 檔案

您亦可選擇手動下載 IronPDF JAR 檔案以供獨立使用。

首次建置與執行

IronPdfEngine 二進位檔將在首次執行專案時自動下載。IronPdfEngine 程式將在您首次呼叫任何 IronPDF 函式時啟動,並在應用程式關閉或進入閒置狀態時停止。

將 IronPDF Engine 安裝為 Maven 依賴項

透過將 IronPdfEngine 加入為 Maven 依賴項,二進位檔將在載入依賴項時一併下載:

  • 此方法可避免冗長的啟動流程,因為 IronPdfEngine 二進位檔已預先下載完成。
  • 此外,對於不允許從外部來源下載的部署環境而言,這將是一項優勢。

若您正在開發多平台應用程式,只需將以下一個或多個程式碼片段加入您的 pom.xml 檔案中:

適用於 Windows x64

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

適用於 Windows x86

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

適用於 Linux x64

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

適用於 macOS x64 (Intel)

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

適用於 macOS Arm(Apple Silicon)

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

開始撰寫 Java 程式碼

定義好依賴項後,您可以在 Java 程式碼頂端加入 import com.ironsoftware.ironpdf.* 語句來開始使用。 以下是一個簡單的 HTML 轉 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 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

這是另一個展示 URL 轉 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 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"));
Java

完整的 Main.java 範例

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

更多設定資訊

注意:請注意,所有設定、記錄及授權操作都必須在呼叫任何 IronPDF 方法之前執行。

套用授權金鑰

若要套用您的授權金鑰,請在方法開頭加入以下內容:

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

記錄

IronPDF Java 採用 slf4j 日誌記錄器進行日誌記錄。 若要啟用記錄功能,請使用:

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

若要指定 IronPdfEngine 日誌路徑,請加入:

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

提供授權與技術支援

購買 IronPDF 授權,以便在實際專案中使用。 亦提供 30 天試用授權供試用者使用

如需查看完整的程式碼範例、教學指南、授權資訊及文件,請造訪:IronPDF for Java 資源

如需更多支援或有任何疑問,請聯絡我們的支援團隊

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備好開始了嗎?

版本:2026.6剛剛發布

立即獲取您的免費 30天試用金鑰
無需信用卡或帳戶建立
PDF的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中

有問題嗎?聯繫我們的開發團隊。

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費 即時演示
Booking Badge

全球數百萬工程師的信任

Iron Software的客戶商標
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊始終保持機密。
全球數百萬工程師的信任
Iron Software的客戶商標
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立
PDF的Java Maven程式庫
using Maven 安裝

版本: 2026.6

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.6.1</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.6.1
or
Java PDF JAR
下載 JAR

版本: 2026.6

手動安裝到您的專案中