如何使用 IronPdfEngine

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPdfEngine 是一款 gRPC 伺服器,旨在管理各種 IronPDF 操作,包括創建、寫入、編輯和閱讀 PDF 文件。

{鏈接至 ironpdf.com 上的 IronPDF for Java 下載頁面}

IronPdf for Java 和 IronPdfEngine

IronPdf for Java 需要 IronPdfEngine 才能運行。 Java 代碼只是 IronPdfEngine gRPC 的 API 封裝。 所以當您調用 IronPDF for Java 中的任何方法時,魔法將會在 IronPdfEngine 內部發生!

預設情況下,IronPdf for Java 將啟動 IronPdfEngine 作為子進程,並與其通信直到您的應用程式關閉。

請注意
每個版本的IronPdf for Java都需要特定版本的IronPdfEngine。不支持跨版本兼容性。

使用本地 IronPdfEngine 的 IronPdf for Java

選項 1:在運行時下載 IronPdfEngine

預設情況下,在您將 IronPDF 安裝到 Java 專案後,首次運行 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>
XML

優點

  • 您的應用程式包將會很小。
  • 可以部署在多個平台上

缺點

  • 首次執行時需要連接互聯網。
  • 啟動時間慢

選項 2(建議):將 IronPdfEngine 作為依賴項安裝

IronPdf Java允許您將IronPdfEngine作為依賴項添加。 這些 IronPdfEngine 依賴項會將 IronPdfEngine 打包成一個 .zip 文件,並將自動解壓並使用。

您可以選擇安裝一個或多個 IronPdfEngine 依賴項。

請注意
ironpdfironpdf-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>
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

<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

[{i:(每個依賴項都相當大,因此不建議全部安裝。

優點

  • 更快的啟動時間。
  • 安裝依賴項後,不需要網際網路訪問。

缺點

  • 您的應用程式包將會很大。
  • 需要指定目標平台。

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();
String ironPdfEngineVersion = Settings.getIronPdfEngineVersion();
JAVA

如何連接

假設 IronPdfEngine 已在遠端運行,位址為 123.456.7.8:33350

參考如何提取和運行 IronPdfEngine 的說明

您只需要告訴IronPdf IronPdfEngine的位置(請確保該地址可以訪問,且未被防火牆阻擋)。 在應用程式的初始階段(或在調用任何IronPdf方法之前),添加此代碼。

com.ironsoftware.ironpdf.Settings.setIronPdfEngineHost("123.456.7.8");
com.ironsoftware.ironpdf.Settings.setIronPdfEnginePort(33350);
com.ironsoftware.ironpdf.Settings.setIronPdfEngineHost("123.456.7.8");
com.ironsoftware.ironpdf.Settings.setIronPdfEnginePort(33350);
JAVA

就是這麼簡單! 之後,您的應用程式將連接到遠端的IronPdfEngine!

對於遠端IronPdfEngine,無需將IronPdfEngine安裝為依賴項。 您可以跳過標題為「選項2(推薦)作為依賴項安裝IronPdfEngine」的部分。