如何使用 IronPdfEngine。
IronPdfEngine 是一个 gRPC 服务器,旨在管理各种 IronPDF 操作,包括创建、编写、编辑和读取 PDF。
如何将 IronPdfEngine 用作远程服务器
- 安装 Java 库以使用 IronPdfEngine
- 在 pom.xml 文件中包含库
- Utilize the `setIronPdfEngineHost` method to configure the host
- Utilize the `setIronPdfEnginePort` method to configure the port
- 使用 IronPdfEngine 将 HTML 渲染成 PDF,渲染器与 Chrome 浏览器相同
在 IronPDF.com 上下载 IronPDF for Java 的链接。
用于Java的IronPdf和IronPdfEngine
IronPDF for Java 需要 IronPdfEngine 才能运行。 Java 代码可作为 IronPdfEngine gRPC 的 API 屏蔽。 当您调用 IronPdf for Java 中的任何方法时,实际处理发生在 IronPdfEngine 内部!
默认情况下,IronPDF for Java 将作为子进程生成 IronPdfEngine 并与之交互,直至应用程序关闭。
使用本地 IronPdfEngine 的 IronPDF for Java.
选项 1:在运行时下载 IronPdfEngine。 默认情况下,在您的 Java 项目中安装 IronPDF 后,首次运行时,IronPDF 会检测您的平台(如 Windows x64),并从互联网上下载相应的 IronPdfEngine 二进制文件。
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>20xx.xx.xx</version>
</dependency><dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>20xx.xx.xx</version>
</dependency>Pros
- 您的申请包将很小。
- 可在多种平台上部署。
Cons
- 首次运行需要互联网接入。
- 启动时间慢。
方案 2(推荐):将 IronPdfEngine 作为依赖项安装。 IronPDF for Java 允许您直接将 IronPdfEngine 作为依赖关系添加。 这些依赖项将 IronPdfEngine 打包成一个 .zip 文件,自动提取并使用它。
您可以选择安装一个或多个 IronPdfEngine 依赖项。
ironpdf 和 ironpdf-engine-xxx-xxx 的依赖版本必须相同。 ironpdf-engine-xxx-xxx 并非指 IronPdfEngine 的内部版本。适用于 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>适用于 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>适用于 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>适用于 macOS x64.
<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>适用于 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>Pros
- 更快的启动时间。
- 安装依赖项后无需访问互联网。
Cons
- 您的申请文件包将很大。
- 需要指定目标平台。
使用远程 IronPdfEngine 的 IronPDF for Java.
要使用远程 IronPdfEngine,需要特定的版本。 例如,如果 IronPDF for Java 版本 2024.2.2 需要 IronPdfEngine 版本 2024.2.2,请勿使用版本 2024.2.1。使用 getIronPdfEngineVersion 方法验证所需的版本。
// Get the version of the IronPdfEngine needed for the current Java version
String ironPdfEngineVersion = Settings.getIronPdfEngineVersion();// Get the version of the IronPdfEngine needed for the current Java version
String ironPdfEngineVersion = Settings.getIronPdfEngineVersion();如何连接
假设 IronPdfEngine 在 123.456.7.8:33350 远程运行。
要连接,请指定 IronPdfEngine 的位置(确保该地址可访问且未被防火墙屏蔽)。 在应用程序的初始阶段(或调用任何 IronPdf 方法之前)添加此代码。
// Set the host and port for a remote IronPdfEngine connection
com.ironsoftware.ironpdf.Settings.setIronPdfEngineHost("123.456.7.8");
com.ironsoftware.ironpdf.Settings.setIronPdfEnginePort(33350);// Set the host and port for a remote IronPdfEngine connection
com.ironsoftware.ironpdf.Settings.setIronPdfEngineHost("123.456.7.8");
com.ironsoftware.ironpdf.Settings.setIronPdfEnginePort(33350);就这么简单! 执行该代码后,您的应用程序将连接到远程 IronPdfEngine!
对于远程 IronPdfEngine,无需将 IronPdfEngine 作为依赖项进行安装。
常见问题解答
什么是 IronPdfEngine,它与 Java PDF 操作有什么关系?
IronPdfEngine 是一个 gRPC 服务器,负责 PDF 操作,如创建、编辑和读取。在 Java 中,它充当 IronPDF 的后端,IronPDF 是 IronPdfEngine 的 API 屏蔽。
如何在 Java 中使用 IronPdfEngine 将 HTML 渲染为 PDF?
您可以在 Java 中使用 IronPDF 库将 HTML 渲染为 PDF。该过程包括设置 IronPdfEngine 并使用其方法,例如 RenderHtmlAsPdf,将 HTML 内容转换为 PDF 格式。
为什么 Java PDF 操作需要与 IronPdfEngine 的版本兼容性?
版本兼容性至关重要,因为每个版本的 IronPDF for Java 都旨在与特定版本的 IronPdfEngine 配合使用,确保操作无缝且避免兼容性问题。
在 Java 项目中本地使用 IronPdfEngine 有哪些优势?
在本地使用 IronPdfEngine 可提高启动速度并消除安装后需要互联网访问的需求。它允许直接在 Java 应用程序中更高效地处理 PDF。
如何在 Java 中配置 IronPdfEngine 用于远程服务器使用?
要配置 IronPdfEngine 远程使用,在 Java 应用程序中使用 setIronPdfEngineHost 和 setIronPdfEnginePort 方法设置服务器的主机和端口,确保服务器可访问。
在运行时决定下载 IronPdfEngine 二进制文件时应该考虑什么?
在运行时下载二进制文件可以使应用程序包更小且具有跨平台部署的灵活性。然而,这需要初次访问互联网且可能导致启动时间较长。
IronPdfEngine 可以在不作为依赖项安装的情况下使用吗?
是的,可以在运行时下载必要的二进制文件而不需要安装 IronPdfEngine 作为依赖项。这种方法适合应用程序大小是一个关注点的动态环境。
如何确保我的 Java PDF 库使用的是正确的 IronPdfEngine 版本?
您可以使用 getIronPdfEngineVersion 方法验证 Java PDF 库所需的 IronPdfEngine 版本,确保兼容性和正确功能。
安装 IronPdfEngine 在 Java 项目的步骤是什么?
要安装 IronPdfEngine,请在项目中包含 IronPDF for Java 库,配置服务器的主机和端口,并在应用程序代码中使用适当的设置连接到 IronPdfEngine。
在 Java 中使用 IronPdfEngine 是否需要互联网访问?
在选择在运行时下载 IronPdfEngine 二进制文件时需要互联网访问。但是,如果将 IronPdfEngine 安装为依赖项,则在初步设置之后不再需要互联网访问。
IronPDF 是否兼容 .NET 10?兼容 .NET 10 能带来哪些好处?
是的。IronPDF 无需任何变通方案即可支持 .NET 10,从而提供更高的性能、更好的运行时稳定性以及对新语言特性的兼容性。它可与所有现代 .NET 版本无缝协作,包括 .NET 8、9 和 10。







