如何使用 IronPdfEngine

Darrius Serrant
Darrius Serrant
2024年2月25日
已更新 2024年12月10日
分享:
This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPdfEngine 是一個 gRPC 伺服器,專門用於管理 IronPDF 的各種任務,包括創建、編輯和閱讀 PDF 文件。

開始使用 IronPDF

立即在您的專案中使用IronPDF,並享受免費試用。

第一步:
green arrow pointer


IronPdf Node.js 和 IronPdfEngine

IronPdf for Node.js require IronPdfEngine 來運行。 Node.js 代码只是 IronPdfEngine gRPC 的 API 掩码。 因此,當您在IronPDF for Node.js中調用任何方法時,魔法將在IronPdfEngine內部發生!

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

請注意
每個版本的 IronPDF for Node.js 都需要特定版本的 IronPdfEngine。不支援跨版本。

Node.js 版 IronPDF 與本地 IronPdfEngine

選項1 在運行時下載 IronPdfEngine

預設情況下,在您將 IronPDF 安裝到 Java 專案後,首次運行 IronPDF 時,將會偵測您的平台(例如 Windows x64),並從網路下載正確的 IronPdfEngine 二進位檔。

npm i @ironsoftware/ironpdf

優點

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

缺點

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

選項 2(推薦)將 IronPdfEngine 安裝為依賴項

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

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

請注意
ironpdfironpdf-engine-xxx-xxx 的相依性版本必須相同。

ironpdf-engine-xxx-xxx依賴項版本並不指代內部的IronPdfEngine版本。

適用於 Windows x64

npm install @ironsoftware/ironpdf-engine-windows-x64

適用於 Windows x86

npm install @ironsoftware/ironpdf-engine-windows-x86

適用於 Linux x64

npm install @ironsoftware/ironpdf-engine-linux-x64

適用於 macOS x64

npm install @ironsoftware/ironpdf-engine-macos-x64

適用於 macOS ARM

npm install @ironsoftware/ironpdf-engine-macos-arm64

請注意
每個依賴項都相當龐大,全都安裝不是個好主意。

優點

  • 啟動時間更快。
  • 在安裝依賴後,不需要互聯網訪問。

缺點

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

IronPdf for Node.js 與遠端 IronPdfEngine

要使用遠端 IronPdfEngine,需要特定版本的 IronPdfEngine。 例如,如果IronPdf for Node.js 版本2024.2.2需要IronPdfEngine版本2024.2.2,請勿使用IronPdfEngine版本2024.2.1。訪問ironPdfEngineVersion屬性以檢查所需的版本。

const ironPdfEngineVersion = IronPdfGlobalConfig.ironPdfEngineVersion;
JAVASCRIPT

如何連接

假設 IronPdfEngine 以遠端方式運行,位於 123.456.7.8:33350

請注意
要遠端運行IronPdfEngine,請參考「如何提取和運行IronPdfEngine」。

您只需要告訴 IronPdf IronPdfEngine 的位置(請確保該地址可訪問,未被防火牆阻擋)。

在應用程式的初始階段(或在調用任何IronPdf方法之前),添加此代碼。

IronPdfGlobalConfig.setConfig({
    ironPdfEngineDockerAddress:"123.456.7.8:33350"
});
JAVASCRIPT

就是這麼簡單! 完成此步驟後,您的應用程式將連接到遠程 IronPdfEngine!

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

Darrius Serrant
全端軟體工程師(WebOps)

Darrius Serrant 擁有邁阿密大學的計算機科學學士學位,目前擔任 Iron Software 的全端 WebOps 行銷工程師。自幼對編程產生興趣,他認為計算機既神秘又易於接觸,使其成為創造力和解決問題的完美媒介。

在 Iron Software,Darrius 享受創造新事物並簡化複雜概念使其更易理解的過程。作為我們的其中一位常駐開發人員,他也自願教導學生,將他的專業知識傳授給下一代。

對 Darrius 來說,他的工作之所以令人滿足,是因為它受到重視並且產生了真正的影響。