How to Redact Regions in PDF Files

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

Redacting sensitive information in PDF documents is crucial for ensuring privacy and compliance with data protection regulations. The [POST] Redact Region API from IronSecure Doc offers an efficient way to hide sensitive text and information in specific regions of a PDF document using true redaction. This API ensures that the redacted data is completely removed and cannot be recovered, making it ideal for handling confidential information in legal, financial, or personal documents.

Pull and Start IronSecureDoc

If you don't have IronSecureDoc running yet, please follow the links below to get it set up:

Host Locally Deploy to Cloud

The [POST] Redact Region API

The [POST] Redact Region API endpoint allows you to hide sensitive information within specific regions of a PDF document using true redaction. This feature is crucial for applications that manage confidential documents, such as legal contracts, medical records, or financial statements. By leveraging this API, you can ensure that sensitive text within defined areas of a PDF is permanently removed, offering both security and compliance.

ご注意Once a region is redacted, the content within that area cannot be recovered.

Trying It Out in Swagger

Swagger is a powerful tool that enables developers to interact with RESTful APIs through a user-friendly web interface. Whether you're using languages like Python, Java, or others, Swagger offers a convenient way to test and implement this API.

Steps to Redact Region with Swagger

  1. Access the Swagger UI:

    If your API server is running locally, you can access Swagger by navigating to http://localhost:8080/swagger/index.html in your web browser.

    Swagger docs

  2. Locate the [POST] Redact Region API:

    Within the Swagger UI, find the [POST] /v1/document-services/pdfs/redact-region endpoint.

    Redact regions

  3. Specify Redaction Coordinates:

    In this example, we will remove a table from the PDF on page index 1 (i.e., Page #2). Use the following coordinates to define the redaction region:

    • Page index (specific_pages): 1
    • X Coordinate (region_to_redact_x): 60
    • Y Coordinate (region_to_redact_y): 270
    • Width (region_to_redact_w): 470
    • Height (region_to_redact_h): 200
  4. Set Optional Parameters:

    Optionally, you can add a user or owner password, specify specific pages, or decide whether to draw a black box over the redacted area and save the document with PDF/A or PDF/UA compliance.

    Input Swagger

  5. Upload a Sample PDF:

    In the request body, upload a sample PDF file where you want to apply the redaction. Ensure that the file is added as pdf_file.

  6. Execute the Request:

    Click "Execute" to run the request. The response will include the redacted PDF, with the table removed from page index 1 as specified.

    Response

    This Swagger UI interaction allows you to easily test the redaction process, providing immediate feedback on how the coordinates affect the PDF content.

  7. Check the Output PDF:

    The redacted region will be on page 2.


Understanding Input Parameters

Before using this API, it's essential to understand the input parameters required and optional for redacting a region in your PDF. These parameters help define the specific area to redact.

Key Parameters

  • pdf_file: The PDF document you want to redact.
  • region_to_redact_x: X coordinate of the region to redact (starting from the bottom-left of the page).
  • region_to_redact_y: Y coordinate of the region to redact (starting from the bottom-left of the page).
  • region_to_redact_w: Width of the region to redact.
  • region_to_redact_h: Height of the region to redact.

Optional Parameters

  • user_password: If the PDF is password-protected, provide the user password.
  • owner_password: Provide the owner password if modifications are restricted.
  • specific_pages: Specify which pages to redact. If not provided, the redaction applies to all pages.
  • save_as_pdfa: Save the PDF with PDF/A-3 compliance.
  • save_as_pdfua: Save the PDF with PDF/UA compliance.

API Integration: Python Example

Once you're familiar with the parameters, you can call this API using your preferred programming language. Below is an example of how to integrate this API using Python.

import requests

# Define the API endpoint URL
url = 'http://localhost:8080/v1/document-services/pdfs/redact-region'

# Set the headers for the request (optional relevant metadata)
headers = {
    'accept': '*/*',
    'author': 'IronSoftware',
    'title': 'REDACT REGION DEMO 2024',
    'subject': 'DEMO EXAMPLE'
}

# Open the PDF file to be redacted in binary read mode
files = {
    'pdf_file': ('sample_file.pdf', open('sample_file.pdf', 'rb'), 'application/pdf')
}

# Define the coordinates and page for the redaction region
data = {
    'region_to_redact_x': '60',  # X-coordinate starting at the bottom-left
    'region_to_redact_y': '270', # Y-coordinate starting at the bottom-left
    'region_to_redact_w': '470', # Width of the region to be redacted
    'region_to_redact_h': '200', # Height of the region to be redacted
    'specific_pages': [1]        # Specify the page index to redact
}

# Make the POST request to the API with the provided parameters and file
response = requests.post(url, headers=headers, files=files, data=data)

# Save the redacted PDF response to a new file
with open('redacted_output.pdf', 'wb') as f:
    f.write(response.content)

print('PDF redacted successfully.')
import requests

# Define the API endpoint URL
url = 'http://localhost:8080/v1/document-services/pdfs/redact-region'

# Set the headers for the request (optional relevant metadata)
headers = {
    'accept': '*/*',
    'author': 'IronSoftware',
    'title': 'REDACT REGION DEMO 2024',
    'subject': 'DEMO EXAMPLE'
}

# Open the PDF file to be redacted in binary read mode
files = {
    'pdf_file': ('sample_file.pdf', open('sample_file.pdf', 'rb'), 'application/pdf')
}

# Define the coordinates and page for the redaction region
data = {
    'region_to_redact_x': '60',  # X-coordinate starting at the bottom-left
    'region_to_redact_y': '270', # Y-coordinate starting at the bottom-left
    'region_to_redact_w': '470', # Width of the region to be redacted
    'region_to_redact_h': '200', # Height of the region to be redacted
    'specific_pages': [1]        # Specify the page index to redact
}

# Make the POST request to the API with the provided parameters and file
response = requests.post(url, headers=headers, files=files, data=data)

# Save the redacted PDF response to a new file
with open('redacted_output.pdf', 'wb') as f:
    f.write(response.content)

print('PDF redacted successfully.')
PYTHON

This code performs the following steps:

  • Load the PDF: The PDF file to be redacted is loaded from the local file system.
  • Set Redaction Parameters: Specify the coordinates (X, Y), width, height, and specific page to redact.
  • Call the API: The [POST] Redact Region API is called, passing in the necessary parameters.
  • Save the Result: The redacted PDF is saved as a new file.

The given region is redacted as shown below.

Redacted output

よくある質問

PDFファイル内の特定の領域をどのように編集できますか?

IronSecureDocの[POST]領域編集APIを使用してPDFファイル内の特定の領域を編集できます。編集領域の座標と寸法を指定することで、APIは機密情報がドキュメントから永久に削除されることを保証します。

IronSecureDocのAPIを編集のために設定するにはどのような手順が必要ですか?

IronSecureDocのAPIを編集のために設定するには、Dockerイメージをプル&スタートし、Swaggerを使用してAPIを設定し、編集のパラメータを指定し、PDFドキュメントの領域を編集するためのAPI呼び出しを実行する必要があります。

IronSecureDocはクラウドプラットフォームで使用できますか?

はい、IronSecureDocはAzureやAWSといったクラウドプラットフォームにデプロイでき、スケーラブルで柔軟な編集ソリューションを提供します。

IronSecureDocを使用してPDFのどの領域を編集するかをどのように指定しますか?

IronSecureDocを使用して編集する領域を指定するには、編集対象となる領域のX座標とY座標、幅、高さを提供する必要があります。これらのパラメータがPDFページ上の正確なエリアを定義します。

完全な実装前に編集プロセスをテストする方法はありますか?

はい、IronSecureDoc APIサーバーをローカルで実行し、Swaggerを使用してAPIと対話することで編集プロセスをテストできます。これにより、編集パラメータを実験して出力を検証し、フルスケールの実装前に確認できます。

どのプログラミング言語をIronSecureDoc APIと統合するために使用できますか?

IronSecureDoc APIは、Python、Java、C#、その他のHTTPリクエストを行うことのできる任意のプログラミング言語と統合することができます。

PDFの真の編集とは何であり、なぜ重要ですか?

PDFの真の編集は、機密データが隠されるだけでなく、ドキュメントから完全に削除されることを保証します。これは、機密保持を維持し、データ保護規制を遵守するために重要です。

IronSecureDocはPDFのコンプライアンス標準をサポートしていますか?

はい、IronSecureDocを使用して編集したPDFを保存する際に、PDF/A-3やPDF/UAなどの標準に準拠することができ、特定のドキュメント要件を満たすことができます。

IronSecureDocは編集のためにパスワード保護されたPDFを処理できますか?

はい、IronSecureDocは、編集プロセス中に必要なユーザーパスワードとオーナーパスワードを任意のパラメータとして提供することにより、パスワード保護されたPDFを処理できます。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
バージョン: 2024.10 ただ今リリースされました