如何使用 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下載IronPDF Java 版
IronPDF for Java 和 IronPdfEngine
Java 版IronPDF需要IronPdfEngine 才能運作。 Java 程式碼用作 IronPdfEngine gRPC 的 API 遮罩。 當您在IronPDF 適用於 Java 中呼叫任何方法時,實際處理將在 IronPdfEngine 內部進行!
預設情況下,Java 版IronPDF會將 IronPdfEngine 作為子進程啟動,並與其交互,直到應用程式關閉為止。
每個 Java 版IronPDF都需要特定版本的 IronPdfEngine。不支援跨版本相容。
使用本地 IronPdfEngine 的 Java 版IronPDF
選項 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>
優點
您的申請包會很小。
- 可部署在多個平台上。
缺點
- 首次運作需要連接網路。 啟動速度慢。
選項 2(建議):將 IronPdfEngine 安裝為依賴項 IronPDF 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>
每個依賴項都相當大,因此不建議全部安裝。
優點
啟動速度更快。 安裝完依賴項後,無需連接網路。
缺點
您的申請文件會很大。
- 需要指定目標平台。
適用於 Java 的IronPDF和遠端 IronPdfEngine
要使用遠端 IronPdfEngine,需要特定版本。 例如,如果IronPDF 適用於 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 版本,確保兼容性和正常運行。
在 Java 項目中安裝 IronPDFEngine 的步驟是什麼?
要安裝 IronPDFEngine,在您的項目中包含 IronPDF for Java 庫,配置服務器的主機和端口,並使用應用代碼中的適當設置連接到 IronPDFEngine。
在 Java 中使用 IronPDFEngine 時,是否必須能夠訪問互聯網?
當選擇在運行時下載 IronPDFEngine 二進制文件時需要互聯網訪問。然而,如果 IronPDFEngine 作為依賴項安裝,在初始設置後不需要互聯網訪問。
IronPDF 是否相容於 .NET 10?相容 .NET 10 能帶來哪些好處?
是的。 IronPDF 無需任何變通方案即可支援 .NET 10,提供更高的效能、更好的執行時間穩定性以及對新語言特性的兼容性。它可與所有現代 .NET 版本無縫協作,包括 .NET 8、9 和 10。

