How to Redact Text in C# PDF with IronSecureDoc
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.
How to Redact Text on PDF with IronSecureDoc
- Pull and start the IronSecureDoc Docker Image
- Test the API using Swagger
- Specify the text to be redacted
- Execute the API call with the provided details
- Export the redacted PDF document
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 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. Using this API ensures that specific text is permanently removed, providing enhanced security and ensuring compliance with data protection standards.
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
-
Access the Swagger UI:
If your API server is running locally, you can access Swagger by navigating to
http://localhost:8080/swagger/index.htmlin your web browser.
-
Locate the [POST] Redact Text API:
Within the Swagger UI, find the
POST/v1/document-services/pdfs/redact-textendpoint.
-
Specify Configurations:
In this example, I am providing both the PDF file and the words to redact in the
POSTrequest. 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:truematch_whole_word:truewords_to_redact: we
-
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. -
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'
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
| Name | Data Type | Description |
|---|---|---|
pdf_file | application/pdf | The PDF file you want to manipulate. |
words_to_redact | array[string] | This parameter takes a list of words and redacts the text matching the input. |
Optional Request Body Parameters
| Name | Data Type | Description |
|---|---|---|
user_password | string | This 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_password | string | This 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_pages | array[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_box | boolean | Allows you to specify whether to draw a black box over the redacted text. By default, this value is set to True. |
match_whole_word | boolean | Specifies 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_case | boolean | Specifies 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_text | string | It specifies the overlay text, such as words or symbols, over the redacted text. By default, this string is empty. |
save_as_pdfa | boolean | Saves the modified PDF with PDF/A-3 compliance. By default, this is set to False. |
save_as_pdfua | boolean | Saves the modified PDF with PDF/UA compliance. By default, this is set to False. |
Optional Header Parameters
| Name | Data Type | Description |
|---|---|---|
author | string | Useful for identifying you as the author of the PDF document. By default, this field is empty. |
title | string | Displays the title of the PDF document. By default, this field is empty. |
subject | string | Useful for identifying the content of the PDF document at a glance. By default, this field is empty. |
Frequently Asked Questions
How can I redact text in a PDF using IronSecureDoc?
You can use IronSecureDoc to redact text by making a `POST` request to the IronSecureDoc server with the PDF file. The API allows for easy and customizable text redaction and returns the redacted PDF.
What are the steps to redact text using Swagger with IronSecureDoc?
To redact text using Swagger with IronSecureDoc, you need to access the Swagger UI, locate the `POST` Redact Text API, specify configurations like the words to redact, upload a sample PDF, and execute the request to receive the redacted PDF.
Is it possible to use the command prompt for redacting text with IronSecureDoc?
Yes, you can use a `curl` `POST` request through the command prompt to achieve text redaction with IronSecureDoc. Ensure the proper parameters, such as `pdf_file` and `words_to_redact`, are included in the request.
What are some optional parameters available for the IronSecureDoc text redaction API?
Optional parameters for the IronSecureDoc API include `draw_black_box`, `match_whole_word`, `overlay_text`, `save_as_pdfa`, and `save_as_pdfua`, allowing you to customize how the text is redacted.
Can IronSecureDoc redact specific pages of a PDF document?
Yes, IronSecureDoc allows the specification of `specific_pages` where the text redaction should occur, providing flexibility in targeting precise areas of a document.
What is the significance of using IronSecureDoc for text redaction in PDFs?
IronSecureDoc ensures that redacted text is permanently removed from PDFs. This enhances security and compliance with data protection standards for confidential documents like legal or financial records.
Can I host IronSecureDoc locally or deploy it on the cloud?
IronSecureDoc can be hosted locally on platforms like Windows, Mac, and Linux, or deployed on cloud services such as Azure and AWS for flexible integration.
What is the function of the `draw_black_box` option in IronSecureDoc?
The `draw_black_box` option in IronSecureDoc allows you to place a black box over redacted text for visual concealment, which is enabled by default.
How does IronSecureDoc handle password-protected PDFs?
For password-protected PDFs, IronSecureDoc requires `user_password` or `owner_password` parameters to perform redactions, ensuring authorized access and manipulation.
What tools can be used to interact with IronSecureDoc's API?
Tools like Swagger UI and command-line tools, such as `curl`, can be used to interact with IronSecureDoc's API for testing and implementing text redaction functionality.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.