如何使用 IronPdfEngine
IronPdfEngine 是一款 gRPC 伺服器,旨在管理各種 IronPDF 操作,包括創建、寫入、編輯和閱讀 PDF 文件。
如何將 IronPdfEngine 作為遠程伺服器使用
- 安裝 Java 函式庫以使用 IronPdfEngine
- 在pom.xml文件中包含該庫
- 利用 setIronPdfEngineHost 方法配置主機
- 使用 setIronPdfEnginePort 方法來配置埠
- 使用IronPdfEngine以與Chrome相同的渲染器將HTML渲染為PDF
{IronPDF for Java 下載連結在 ironpdf.com}
IronPdf for Java 和 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>
優點
- 您的應用程式包將會很小。
- 可以部署在多個平台上
缺點
- 首次執行時需要連接互聯網。
- 啟動時間慢
選項 2(建議):將 IronPdfEngine 作為依賴項安裝
IronPdf Java允許您將IronPdfEngine作為依賴項添加。 這些 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>
適用於 Windows x86
<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>
適用於 macOS x64
<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>
請注意
優點
- 更快的啟動時間。
- 安裝依賴項後,不需要網際網路訪問。
缺點
- 您的應用程式包將會很大。
- 需要指定目標平台。
IronPdf for Java 搭配遠端 IronPdfEngine
要使用遠端的IronPdfEngine,需要特定版本的IronPdfEngine。 例如,如果 IronPDF for Java 版本 2024.2.2 需要 IronPdfEngine 版本 2024.2.2,請勿使用 IronPdfEngine 版本 2024.2.1。請使用 getIronPdfEngineVersion
方法檢查所需版本。
String ironPdfEngineVersion = Settings.getIronPdfEngineVersion();
如何連接
假設 IronPdfEngine 正在 123.456.7.8:33350
遠端運行。
您只需告訴 IronPdf 其中的 IronPdfEngine 位置(請確保該地址可訪問,沒有被防火牆阻擋。). 在您的應用程序的初始階段添加此代碼(或在調用任何 IronPDF 方法之前).
com.ironsoftware.ironpdf.Settings.setIronPdfEngineHost("123.456.7.8");
com.ironsoftware.ironpdf.Settings.setIronPdfEnginePort(33350);
就是這麼簡單! 之後,您的應用程式將連接到遠端 IronPdfEngine!
對於遠端IronPdfEngine,無需將IronPdfEngine安裝為依賴項。 您可以跳過名為的部分。選項 2(推薦)將 IronPdfEngine 安裝為依賴項.