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 关于 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> <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函数时启动,并在您的应用程序关闭或进入空闲状态时停止。 作为 Maven 依赖项安装 IronPDF 引擎 通过将 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(苹果芯片) <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 for 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 资源。 如需更多支持和查询,请联系我们的支持团队。 Darrius Serrant 立即与工程团队聊天 全栈软件工程师(WebOps) Darrius Serrant 拥有迈阿密大学的计算机科学学士学位,目前在 Iron Software 担任全栈 WebOps 市场工程师。从小就被编码吸引,他认为计算机既神秘又易于接触,使其成为创意和问题解决的理想媒介。在 Iron Software,Darrius 喜欢创造新事物,并简化复杂概念以使其更易理解。作为我们常驻的开发者之一,他还自愿教授学生,与下一代分享他的专业知识。对于 Darrius 来说,他的工作令人满意,因为它被重视并产生真正的影响。 准备开始了吗? 版本: 2026.3 刚刚发布 免费试用 免费 Maven 下载 查看许可证 还在滚动吗? 想快速获得证据? 运行示例看着你的HTML代码变成PDF文件。 免费 Maven 下载 查看许可证