IronPDF 文檔 入門 IronPDF for Java - 在 Java 應用程式中建立、編輯和讀取 PDF Darrius Serrant 更新:2025年7月22日 下載 IronPDF Maven 下載 JAR 下載 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English 關於 Java 版IronPDF 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> <dependency> <groupId>com.ironsoftware</groupId> <artifactId>ironpdf</artifactId> <version>20xx.xx.xxxx</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>2.0.3</version> </dependency> </dependencies> <dependencies> <dependency> <groupId>com.ironsoftware</groupId> <artifactId>ironpdf</artifactId> <version>20xx.xx.xxxx</version> </dependency> <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> <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> <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> <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> <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> <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")); // 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")); // 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")); } } 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"); com.ironsoftware.ironpdf.License.setLicenseKey("YOUR-LICENSE-KEY"); JAVA 日誌記錄 IronPDF Java 使用slf4j 日誌記錄器進行日誌記錄。 若要啟用日誌記錄,請使用: com.ironsoftware.ironpdf.Settings.setDebug(true); com.ironsoftware.ironpdf.Settings.setDebug(true); JAVA 若要指定 IronPdfEngine 日誌路徑,請新增: com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log")); com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log")); JAVA 提供許可和支持 購買IronPDF許可證,即可在實際項目中使用。 我們也為試用用戶提供 30 天試用許可證。 如需查看完整的程式碼範例、教學課程、許可資訊和文檔,請造訪: IronPDF for Java resources 。 如需更多協助或有任何疑問,請聯絡我們的支援團隊。 Darrius Serrant 立即與工程團隊聊天 全棧軟件工程師 (WebOps) Darrius Serrant 擁有邁阿密大學計算機科學學士學位,目前任職於 Iron Software 的全栈 WebOps 市場營銷工程師。從小就迷上編碼,他認為計算既神秘又可接近,是創意和解決問題的完美媒介。在 Iron Software,Darrius 喜歡創造新事物,並簡化複雜概念以便於理解。作為我們的駐場開發者之一,他也自願教學生,分享他的專業知識給下一代。對 Darrius 來說,工作令人滿意因為它被重視且有實際影響。 準備好開始了嗎? 版本: 2026.3 剛剛發布 開始免費試用 免費 Maven 下載 查看許可證 還在捲動嗎? 想要快速證明? 執行範例 觀看您的 HTML 變成 PDF。 免費 Maven 下載 查看許可證