如何在 Google Cloud 中運行 IronPDF for Java

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

Note: We have not fully tested support with Google Cloud, but if you want to try, we have some Required Settings.

重要提示:必需設置

  • 由於 IronPDF 需要在執行時間執行二進位文件,因此不支援 Zip 部署。
  • 預設的雲端函數 Docker 映像無法正常運作,因為它們缺少 Chrome 正常運作所需的軟體包。 有關更多信息,請參閱Google Cloud 系統包。 請使用自訂 Dockerfile 並安裝所有必要的軟體包。 請參閱我們的Linux 部署指南,以了解更多資訊。

  • ironpdf-engine-linux-x64依賴項新增至您的專案(將版本編號變更為最新版本):

    <dependency>
      <groupId>com.ironsoftware</groupId>
      <artifactId>ironpdf-engine-linux-x64</artifactId>
      <version>2022.xx.x</version>
    </dependency>
    <dependency>
      <groupId>com.ironsoftware</groupId>
      <artifactId>ironpdf-engine-linux-x64</artifactId>
      <version>2022.xx.x</version>
    </dependency>
    XML

*可能需要此插件:

  <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.2.4</version>
      <executions>
          <execution>
              <phase>package</phase>
              <goals>
                  <goal>shade</goal>
              </goals>
              <!-- required for Docker -->
              <configuration>
                  <transformers>
                      <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                  </transformers>
              </configuration>
          </execution>
      </executions>
  </plugin>
  <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.2.4</version>
      <executions>
          <execution>
              <phase>package</phase>
              <goals>
                  <goal>shade</goal>
              </goals>
              <!-- required for Docker -->
              <configuration>
                  <transformers>
                      <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                  </transformers>
              </configuration>
          </execution>
      </executions>
  </plugin>
XML

*可能需要以下相依性:

  <dependency>
      <groupId>io.perfmark</groupId>
      <artifactId>perfmark-api</artifactId>
      <version>0.26.0</version>
  </dependency>

  <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-okhttp</artifactId>
      <version>1.50.2</version>
  </dependency>

  <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-netty-shaded</artifactId>
      <version>1.50.2</version>
  </dependency>
  <dependency>
      <groupId>io.perfmark</groupId>
      <artifactId>perfmark-api</artifactId>
      <version>0.26.0</version>
  </dependency>

  <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-okhttp</artifactId>
      <version>1.50.2</version>
  </dependency>

  <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-netty-shaded</artifactId>
      <version>1.50.2</version>
  </dependency>
XML
  • 由於啟動緩慢,請將timeout設定為330 seconds
  • memory size設定為至少2048 MB
  • Ephemeral Storage Size設定為至少1024 MB
  • 在某些環境下,您可能需要指定IronPdfEngineWorkingDirectory並為其設定執行權限:

    // Set the working directory for the IronPDF Engine
    Setting.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
    // Set the working directory for the IronPDF Engine
    Setting.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
    JAVA
    # Grant full read/write/execute permissions to the /tmp directory
    RUN chmod 777 /tmp/

常見問題解答

如何在 Google Cloud 上設定 Java 的 PDF 函式庫?

若要在 Google Cloud 上架設 PDF 函式庫,請使用自訂的 Dockerfile 來安裝所有必要的套件,詳情請參閱 IronPDF Linux 部署指南。包含 ironpdf-engine-linux-x64 相依性,並配置特定設定以獲得最佳效能。

在 Google Cloud 上執行 PDF 函式庫需要哪些特定設定?

在 Google Cloud 上執行 PDF 函式庫時,請使用 330 秒的逾時時間、至少 2048 MB 的記憶體大小,以及至少 1024 MB 的短暫儲存大小。此外,請設定 IronPdfEngineWorkingDirectory 並確保該目錄的執行權限。

為什麼 Google Cloud 上的 PDF 函式庫不支援 Zip 部署?

不支援 Zip 部署,因為 IronPDF 需要在執行時執行二進位檔案,而標準的 Zip 部署方法並不可行。

在 Google Cloud 上部署 PDF 函式庫需要哪些額外的依賴項目?

可能需要的其他相依性包括 perfmark-api, grpc-okhttp, 和 grpc-netty-shaded.這些元件可確保資料庫在部署時能正常運作。

如何處理 Google Cloud Docker 影像中 PDF 函式庫的套件需求?

預設的 Cloud Function Docker 映像檔缺乏 Chrome 所需的套件。請按照 IronPdf.Linux 部署指南中的指示,使用自訂的 Dockerfile 安裝所有必要的套件。

在 Docker 環境中部署 PDF 函式庫是否需要特定的 Maven 外掛程式?

Docker 環境可能需要maven-shade-plugin。應將其設定為使用轉換器,尤其是在處理複雜的相依性時。

如何在 Docker 環境中設定 PDF 引擎的工作目錄?

您可以使用 Setting.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/")) 設定 PDF 引擎的工作目錄。確保您在 Dockerfile 中使用 RUN chmod 777 /tmp/ 之類的指令授予必要的權限。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
版本: 2025.12 剛發表