How to Redact Text on PDF with IronSecureDoc

by Curtis Chau

In this article, we will discuss redacting text on a PDF using IronSecureDoc. This allows the service or process to quickly and easily redact sensitive information by making a simple POST request with the PDF to the running IronSecureDoc server. We will demonstrate this visually through the use of Swagger docs. The POST request takes in both required and optional parameters and is highly customizable; the response returns the PDF with the redacted text.

Pull and Start IronSecureDoc

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

Host LocallyDeploy to Cloud

The [POST] Redact Text API

The [POST] Redact Text API endpoint allows you to hide sensitive text within a PDF document using redaction. This functionality is essential for applications that handle confidential documents, such as legal contracts, medical records, or financial reports. By using this API, you can ensure that specific text is permanently removed, providing enhanced security and ensuring compliance with data protection standards.

Please note
Once a text is redacted, the content cannot be recovered.

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 Text 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

  1. Locate the [POST] Redact Text API:

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

Redact text

  1. Specify Configurations:

In this example, I am providing both the PDF file and the words to redact in the POST request. We will redact the word "we" and overlay a black box on it. For this demonstration, we will use the 'sample.pdf' file with the following configurations:

  • draw_black_box: true
  • match_whole_word: true
  • words_to_redact: we
  1. 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.

  1. Execute the Request:

Click "Execute" to run the request. The response will include the redacted PDF. This Swagger UI interaction allows you to easily test the redaction process, providing immediate feedback.


Use CURL Request through Command Prompt

Alternatively, we can use the Command Prompt with a curl POST request to achieve the same result.

curl -X POST 'http://localhost:8080/v1/document-services/pdfs/redact-text' \
 -H 'accept: */*' \
 -H 'Content-Type: multipart/form-data' \
 -F 'pdf_file=@sample.pdf;type=application/pdf' \
 -F 'words_to_redact="we"' \
 -F 'draw_black_box=true' \
 -F 'match_whole_word=true'

Please note
By default, PowerShell may interpret curl as an alias for Invoke-WebRequest, a built-in PowerShell cmdlet. Try using curl.exe instead of curl.

curl.exe --version

Required Request Body Parameters

NameData TypeDescription
pdf_fileapplication/pdfThe PDF file you want to manipulate.
words_to_redactarray[string]This parameter takes a list of words and redacts the text matching the input.

Optional Request Body Parameters

NameData TypeDescription
user_passwordstringThis is required if the input PDF has a user password. The operation will fail if no password is provided for the password-protected PDF.
owner_passwordstringThis is required if the input PDF has an owner password. The operation will fail if no password is provided for the password-protected PDF.
specific_pagesarray[int]Allows you to specify which pages to redact text on. By default, the value is null, meaning the provided word in all the pages will be redacted.
draw_black_boxbooleanAllows you to specify whether to draw a black box over the redacted text. By default, this value is set to True.
match_whole_wordbooleanSpecifies whether partial matches within words should also be redacted. For example, if the provided word is "are," any words containing "are," such as "hare," will have the "are" redacted as well. By default, this is set to True.
match_casebooleanSpecifies whether the provided word should be an exact match in terms of case. By default, this value is null. Note: Setting this to True means that lowercase and uppercase strings will not be matched. For example, if the provided word is "WE," the lowercase version "we" would not be redacted.
overlay_textstringIt specifies the overlay text, such as words or symbols, over the redacted text. By default, this string is empty.
save_as_pdfabooleanSaves the modified PDF with PDF/A-3 compliance. By default, this is set to False.
save_as_pdfuabooleanSaves the modified PDF with PDF/UA compliance. By default, this is set to False.

Optional Header Parameters

NameData TypeDescription
authorstringUseful for identifying you as the author of the PDF document. By default, this field is empty.
titlestringDisplays the title of the PDF document. By default, this field is empty.
subjectstringUseful for identifying the content of the PDF document at a glance. By default, this field is empty.