IRONSOFTWAREHOME

How to Redact Text in C# PDF with IronSecureDoc

Curtis Chau
Curtis Chau
Updated: July 21, 2026

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:

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.

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

  2. Locate the [POST] Redact Text API:

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

    Redact text

  3. 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
  4. 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.

  5. 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'
SHELL
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
SHELL

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.

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
Technical Writer

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.

...
Read More

Ready to Get Started?

Version:2024.10just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required