如何在 PDF 檔案中遮蔽特定區域 with C
在 PDF 文件中遮蔽敏感資訊,對於確保隱私及遵守資料保護法規至關重要。 IronSecure Doc 提供的 [POST] Redact Region API 提供了一種高效的方式,可透過真正的遮蔽技術,隱藏 PDF 文件中特定區域的敏感文字與資訊。 此 API 可確保經遮蔽處理的資料被徹底移除且無法復原,因此非常適合用於處理法律、財務或個人文件中的機密資訊。
如何在 PDF 檔案中遮蔽特定區域
- 拉取並啟動 IronSecureDoc Docker 映像檔
- 使用 Swagger 試用 API
- 設定參數
- 可使用任何偏好的程式語言呼叫 API
- 下載生成的 PDF 文件
拉取並啟動 IronSecureDoc
若您尚未執行 IronSecureDoc,請點擊下方連結進行設定:
| 本地部署 | 部署至雲端 |
|---|---|
[POST] 區域遮蔽 API
[POST] Redact Region API 端點可讓您透過真正的遮蔽技術,隱藏 PDF 文件中特定區域內的敏感資訊。 此功能對於管理機密文件(例如法律合約、醫療紀錄或財務報表)的應用程式至關重要。 透過運用此 API,您可以確保 PDF 文件中指定區域內的敏感文字被永久移除,同時兼顧安全性與合規性。
在 Swagger 中試用
Swagger 是一款強大的工具,可讓開發人員透過友善的網頁介面與 RESTful API 進行互動。 無論您使用的是 Python、Java 或其他語言,Swagger 都能提供便捷的方式來測試並實作此 API。
使用 Swagger 遮蔽區域的步驟
存取 Swagger UI:
若您的 API 伺服器在本地端運行,您可透過在網頁瀏覽器中導航至
http://localhost:8080/swagger/index.html來存取 Swagger。
定位 [POST]
/v1/document-services/pdfs/redact-region端點:在 Swagger UI 中,找到
POST /v1/document-services/pdfs/redact-region端點。
指定遮蔽座標:
在此範例中,我們將從 PDF 的索引頁 1(即第 2 頁)移除一個表格。 請使用以下座標定義遮蔽區域:
- 頁面索引 (
specific_pages): 1 - X 座標 (
region_to_redact_x): 60 - Y 座標 (
region_to_redact_y): 270 - 字寬 (
region_to_redact_w): 470 - 高度 (
region_to_redact_h): 200
- 頁面索引 (
設定可選參數:
您可選擇性地設定使用者或擁有者密碼、指定特定頁面,或決定是否在遮蔽區域繪製黑色方框,並以符合 PDF/A 或 PDF/UA 標準的格式儲存文件。

上傳範例 PDF:
請在請求內容中上傳一個您希望進行遮蔽處理的樣本 PDF 檔案。 請確保檔案以
pdf_file的格式加入。執行請求:
點擊"執行"以執行請求。回應將包含經處理的 PDF 檔案,其中第 1 頁的表格已依照指定移除。

此 Swagger UI 互動功能讓您能輕鬆測試遮蔽處理流程,並即時提供座標如何影響 PDF 內容的回饋。
檢查輸出 PDF:
被遮蔽的區域將位於第 2 頁。
理解輸入參數
在使用此 API 之前,務必了解在 PDF 中遮蔽特定區域時所需的必填與選填輸入參數。 這些參數有助於界定需進行刪節的具體範圍。
關鍵參數
pdf_file:您要進行遮蔽處理的 PDF 文件。region_to_redact_x:需遮蔽區域的 X 座標(以頁面左下角為起點)。region_to_redact_y:需遮蔽區域的 Y 座標(以頁面左下角為起點)。region_to_redact_w:需遮蔽區域的寬度。region_to_redact_h:需遮蔽區域的高度。
可選參數
user_password:若 PDF 檔案設有密碼保護,請提供使用者密碼。owner_password:若修改權限受限,請提供擁有者密碼。specific_pages:指定需遮蔽的內容頁面。 若未另行指定,此修訂內容適用於所有頁面。save_as_pdfa:以符合 PDF/A-3 標準的方式儲存 PDF 檔案。save_as_pdfua:以符合 PDF/UA 標準的方式儲存 PDF 檔案。
API 整合:Python 範例
熟悉相關參數後,即可使用您偏好的程式語言呼叫此 API。 以下是使用 Python 整合此 API 的範例。
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': 'Iron Software',
'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': 'Iron Software',
'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.')此程式碼執行以下步驟:
- 載入 PDF:將從本機檔案系統載入待遮蔽的 PDF 檔案。
- 設定遮蔽參數:指定要遮蔽的座標 (X, Y)、寬度、高度及特定頁面。
- 呼叫 API:呼叫 [POST] Redact Region API,並傳入必要的參數。
- 儲存結果:經編輯的 PDF 將儲存為新檔案。
指定區域已如以下所示進行遮蔽。

常見問題
如何在PDF文件中遮罩特定區域?
您可以使用IronSecureDoc的[POST] Redact Region API遮罩PDF文件中的特定區域。通過提供遮罩區域的坐標和尺寸,API確保敏感資訊被永久從文件中移除。
設置IronSecureDoc API以進行遮罩涉及哪些步驟?
要設置IronSecureDoc API以進行遮罩,您需要拉取並啟動Docker Image,使用Swagger配置API,指定遮罩參數,並執行API調用以遮罩PDF文件中的區域。
IronSecureDoc可用於雲平台上嗎?
是的,IronSecureDoc可以部署在Azure和AWS等雲平台上,提供可擴展和靈活的遮罩解決方案。
如何指定使用IronSecureDoc遮罩PDF的哪些區域?
要使用IronSecureDoc指定遮罩區域,您需要提供X和Y坐標以及需要遮罩區域的寬度和高度。這些參數定義了PDF頁面上的確切區域。
有沒有辦法在全面實施之前測試遮罩過程?
是的,您可以通過運行IronSecureDoc API伺服器和使用Swagger與API交互來本地測試遮罩過程。這允許您試驗遮罩參數並在全面實施之前驗證輸出。
哪些編程語言可以用於與IronSecureDoc API整合?
IronSecureDoc API可以與任何能夠發送HTTP請求的編程語言整合,如Python、Java、C#等。
什麼是真正的PDF遮罩,為什麼重要?
PDF中的真正遮罩確保敏感資料不僅被隱藏,而且完全從文件中移除。這對於保持保密性和遵守資料保護法規至關重要。
Does IronSecureDoc support PDF compliance standards?
是的,使用IronSecureDoc儲存經過遮罩的PDF時,您可以選擇符合PDF/A-3或PDF/UA等標準,以滿足特定文件要求。
IronSecureDoc能否處理受密碼保護的PDF以進行遮罩?
是的,IronSecureDoc能夠通過在遮罩過程中提供必要的使用者和擁有者密碼作為可選參數來處理受密碼保護的PDF。





