Hosting on Mac

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

IronSecureDoc is a Docker container designed to give you powerful PDF manipulation behind a simple REST API, without the hassle and overhead of online SaaS services. This guide will walk you through the steps to host IronSecureDoc on your machine, including setting up environment variables and a basic example of using the REST API. For the full API, view our REST API Reference.

# Pull the latest IronSecureDoc Docker image
docker pull ironsoftwareofficial/ironsecuredoc:latest
# Pull the latest IronSecureDoc Docker image
docker pull ironsoftwareofficial/ironsecuredoc:latest
SHELL

Prerequisites

警告Docker supports Docker Desktop on the most recent versions of macOS. That is, the current release of macOS and the previous two releases. As new major versions of macOS are made generally available, Docker stops supporting the oldest version and supports the newest version of macOS (in addition to the previous two releases).

Mac with Intel chip

Mac with Apple silicon

Step-by-Step Guide

1. Install Docker Desktop

If you haven't already installed Docker Desktop, follow these steps:

  1. Go to the Docker Desktop download page.
  2. Download the Docker Desktop installer for Mac.
  3. Run the installer and follow the on-screen instructions.
  4. After installation, start Docker Desktop and make sure it's running.

2. Pull the "IronSecureDoc" Docker Image

Open a command line interface and pull the latest IronSecureDoc image from Docker Hub:

# Pull the latest IronSecureDoc image
docker pull ironsoftwareofficial/ironsecuredoc:latest
# Pull the latest IronSecureDoc image
docker pull ironsoftwareofficial/ironsecuredoc:latest
SHELL

3. Run the Container Without Certificate

Run the Docker container with the necessary environment variables:

# Run the Docker container with environment variables
docker container run --rm -p 8080:8080 \
  -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \
  -e ENVIRONMENT=Development \
  -e HTTP_PORTS=8080 \
  ironsoftwareofficial/ironsecuredoc:latest
# Run the Docker container with environment variables
docker container run --rm -p 8080:8080 \
  -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \
  -e ENVIRONMENT=Development \
  -e HTTP_PORTS=8080 \
  ironsoftwareofficial/ironsecuredoc:latest
SHELL

Replace <IRONSECUREDOC_LICENSE_KEY> with your actual IronSecureDoc license key. Otherwise, a watermark will be applied on Enterprise Features.

4. Access the Container

Once the container is running, you can access IronSecureDoc by opening a web browser and navigating to:

http://localhost:8080/swagger/index.html

You should see the IronSecureDoc interface, indicating that your container is running successfully.

5. Run the IronSecureDoc Container With Certificate

If you need to run the container with a certificate, follow these steps to generate the certificate and configure the local machine:

  1. Generate Certificate:

    # Generate and trust HTTPS development certificate
    dotnet dev-certs https -ep $HOME/.aspnet/https/ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>
    dotnet dev-certs https --trust
    # Generate and trust HTTPS development certificate
    dotnet dev-certs https -ep $HOME/.aspnet/https/ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>
    dotnet dev-certs https --trust
    SHELL

    Replace <CREDENTIAL_PLACEHOLDER> with a password.

  2. Run the Docker Container:

    # Run the container with HTTPS support
    docker container run -d -p 8081:8081 -p 8080:8080 \
    -e HTTP_PORTS=8080 -e HTTPS_PORTS=8081 \
    -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \
    -e ENVIRONMENT=Production \
    -v $HOME/.aspnet/https:/https:ro \
    -e CERTIFICATE_PATH=$HOME/.aspnet/https/ironsecuredoc.pfx \
    -e CERTIFICATE_PASSWORD=<CERTIFICATE_PASSWORD> \
    ironsoftwareofficial/ironsecuredoc:latest
    # Run the container with HTTPS support
    docker container run -d -p 8081:8081 -p 8080:8080 \
    -e HTTP_PORTS=8080 -e HTTPS_PORTS=8081 \
    -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \
    -e ENVIRONMENT=Production \
    -v $HOME/.aspnet/https:/https:ro \
    -e CERTIFICATE_PATH=$HOME/.aspnet/https/ironsecuredoc.pfx \
    -e CERTIFICATE_PASSWORD=<CERTIFICATE_PASSWORD> \
    ironsoftwareofficial/ironsecuredoc:latest
    SHELL

    提示Replace <IRONSECUREDOC_LICENSE_KEY> and <CERTIFICATE_PASSWORD> with your actual IronSecureDoc license key and certificate password respectively.

6. Managing the Container

You can manage your running container using Docker commands. Here are a few useful commands:

  • Stop the container:

    docker stop <container_id_or_name>
    docker stop <container_id_or_name>
    SHELL
  • Start the container:

    docker start <container_id_or_name>
    docker start <container_id_or_name>
    SHELL
  • Remove the container:

    docker rm -f <container_id_or_name>
    docker rm -f <container_id_or_name>
    SHELL

Environment Variables

The container can be configured using the following environment variables:

  • PDF_MAX_SIZE_MB (Default: 30): Sets the maximum allowed file size for PDF uploads in Megabytes.
  • REQUEST_TIMEOUT_SECONDS (Default: 5): Sets the timeout duration in seconds for API requests. A value of -1 allows requests to run indefinitely.
  • ALLOWED_ORIGINS: Configures Cross-Origin Resource Sharing (CORS) by specifying allowed origin URLs. Separate multiple URLs with commas. Use * or all to allow requests from any origin.
  • HTTP_PORTS: Defines the HTTP ports the container exposes. This should match the port mapping using the -p flag (e.g., 8080). Separate multiple ports with a semicolon (;).
  • HTTPS_PORTS: Defines the HTTPS ports the container exposes. This should match the port mapping using the -p flag (e.g., 8081). Separate multiple ports with a semicolon (;).
  • IronSecureDoc_LicenseKey (Required): Sets the IronSecureDoc license key. Important: Do not share this value publicly.

Basic Example: Redact Text in a Document

For the full list of API endpoints, refer to the full REST API Reference.

Redact Text

# Redact specific words in a PDF document
curl -X POST 'http://localhost:8080/v1/document-services/pdfs/redact-text' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'pdf_file=@/path/to/your/document.pdf;type=application/pdf' \
  -F 'words_to_redact="sensitiveWord"' \
  -F 'draw_black_box=true' \
  -F 'match_whole_word=true' \
  -F 'match_case=true'
# Redact specific words in a PDF document
curl -X POST 'http://localhost:8080/v1/document-services/pdfs/redact-text' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'pdf_file=@/path/to/your/document.pdf;type=application/pdf' \
  -F 'words_to_redact="sensitiveWord"' \
  -F 'draw_black_box=true' \
  -F 'match_whole_word=true' \
  -F 'match_case=true'
SHELL

Replace /path/to/your/document.pdf with the actual path to the document you want to redact and sensitiveWord with the word you want to redact.

Redact Regular Expression

# Redact text based on a regular expression in a PDF document
curl -X POST 'http://localhost:8080/v1/document-services/pdfs/redact-regular-expression' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'pdf_file=@/path/to/your/document.pdf;type=application/pdf' \
  -F 'regular_expression="[0-9]"' \
  -F 'draw_black_box=true'
# Redact text based on a regular expression in a PDF document
curl -X POST 'http://localhost:8080/v1/document-services/pdfs/redact-regular-expression' \
  -H 'accept: */*' \
  -H 'Content-Type: multipart/form-data' \
  -F 'pdf_file=@/path/to/your/document.pdf;type=application/pdf' \
  -F 'regular_expression="[0-9]"' \
  -F 'draw_black_box=true'
SHELL

Replace /path/to/your/document.pdf with the actual path to the document you want to redact and [0-9] with the regular expression you want to match and redact.

Conclusion

You have successfully hosted IronSecureDoc on your machine and configured it with necessary environment variables. You also learned how to interact with the IronSecureDoc REST API using cURL for both basic and advanced operations. For further configuration and usage details, refer to the full REST API Reference.

常見問題解答

在 macOS 上託管 IronSecureDoc 容器需要哪些步驟?

要在 macOS 上託管 IronSecureDoc 容器,您需要安裝 Docker Desktop,拉取最新的 IronSecureDoc Docker 映像,並配置帶有環境變數的容器,如 IronSecureDoc_LicenseKeyPDF_MAX_SIZE_MBREQUEST_TIMEOUT_SECONDS。詳細說明在教程中提供。

怎樣在 Mac 上使用 HTTPS 運行 IronSecureDoc 容器?

要在 Mac 上以 HTTPS 運行 IronSecureDoc 容器,使用 dotnet dev-certs 生成證書,然後使用包含 -v 用於面積和 -e 用於環境變數的適當命令運行容器,指定證書路徑和密碼。

Docker 容器在 macOS 上運行後,我如何訪問 IronSecureDoc 界面?

當 Docker 容器在 macOS 上運行後,您可以在網頁瀏覽器中訪問 http://localhost:8080/swagger/index.html 以進入 IronSecureDoc 界面。

在 macOS 上安裝 Docker Desktop 的先決條件是什麼?

在 macOS 上安裝 Docker Desktop,確保您的 Mac 使用受支持的 macOS 版本,包括當前版本和前兩個版本。另外,請確保選擇與您的處理器兼容的安裝程序,無論是 Intel 還是 Apple Silicon。

我怎樣才能使用 IronSecureDoc Docker 容器在 PDF 中編輯字或模式?

您可以透過將 POST 請求發送到 IronSecureDoc API 端點,使用 cURL 等工具指定 PDF 文件及要編輯的字或模式來編輯 PDF。

在 macOS 上 IronSecureDoc 容器可以設置什麼環境變數?

IronSecureDoc 容器的環境變數包括 PDF_MAX_SIZE_MBREQUEST_TIMEOUT_SECONDSALLOWED_ORIGINSHTTP_PORTSHTTPS_PORTSIronSecureDoc_LicenseKey

如何在 macOS 上拉取最新的 IronSecureDoc Docker 映像?

要在 macOS 上拉取最新的 IronSecureDoc Docker 映像,請在終端中運行命令:docker pull ironsoftwareofficial/ironsecuredoc:latest

管理 Mac 上的 IronSecureDoc 容器的基本 Docker 命令有哪些?

管理 IronSecureDoc 容器的基本 Docker 命令包括 docker stop docker start docker rm -f

Curtis Chau
技術作家

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

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

準備好開始了嗎?
版本: 2024.10 剛剛發布