How to Redact Text on PDF with IronSecureDoc

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

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

Por favor notaOnce 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'
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

Por favor nota 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
curl.exe --version
SHELL

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.

Preguntas Frecuentes

¿Cómo puedo redactar texto en un PDF usando una solicitud POST?

Puedes redactar texto en un PDF realizando una solicitud POST al servidor IronSecureDoc con el archivo PDF y las palabras que deseas redactar. El servidor procesa la solicitud y devuelve un PDF con el texto redactado.

¿Cuáles son los pasos para usar la API de IronSecureDoc para la redacción de PDF?

Para usar la API de IronSecureDoc para la redacción de PDF, primero debes descargar y comenzar la imagen de Docker de IronSecureDoc, probar la API usando Swagger, especificar el texto para redactar, ejecutar la llamada API y finalmente exportar el documento PDF redactado.

¿Cómo puedo probar la API de IronSecureDoc antes de usarla en producción?

Puedes probar la API de IronSecureDoc usando Swagger accediendo a la interfaz de Swagger, la cual te permite usar los endpoints proporcionados para simular el proceso de redacción.

¿Qué parámetros pueden personalizarse en una solicitud de redacción de PDF?

En una solicitud de redacción de PDF, puedes personalizar parámetros como user_password, owner_password, specific_pages, draw_black_box, match_whole_word, match_case, overlay_text, save_as_pdfa y save_as_pdfua para una mayor personalización.

¿Cómo ejecuto una solicitud de redacción de PDF usando curl?

Para ejecutar una solicitud de redacción de PDF usando curl, puedes usar un comando de solicitud POST de curl, especificando los parámetros necesarios y la ruta del archivo en tu línea de comandos.

¿Qué debo hacer si mi PDF está protegido con contraseña durante la redacción?

Si tu PDF está protegido con contraseña, necesitas incluir el user_password o owner_password en los parámetros opcionales para asegurar que el proceso de redacción pueda acceder y modificar el documento.

¿Cuál es el propósito del parámetro 'draw_black_box' en la redacción de texto?

El parámetro 'draw_black_box' especifica si se cubre el texto redactado con un cuadro negro. Esta opción es útil para visualizar las áreas redactadas y está habilitada por defecto.

¿Cómo puedo alojar IronSecureDoc localmente para fines de redacción?

Puedes alojar IronSecureDoc localmente siguiendo los tutoriales proporcionados para varios sistemas operativos como Windows, Mac o Linux, permitiéndote gestionar el proceso de redacción en tu servidor local.

¿Es posible redactar páginas específicas en un PDF?

Sí, puedes especificar qué páginas redactar usando el parámetro 'specific_pages', el cual te permite dirigir áreas particulares del documento para la redacción.

¿Puedo superponer texto en áreas redactadas en un PDF?

Sí, puedes superponer texto en áreas redactadas usando el parámetro 'overlay_text', el cual te permite reemplazar el texto redactado con un mensaje personalizado o un marcador de posición.

¿IronSecureDoc es compatible con .NET 10 y sus bibliotecas cliente?

Sí, IronSecureDoc proporciona un cliente .NET a través del paquete NuGet IronSoftware.SecureDoc.Client, y es compatible con .NET 10, además de versiones anteriores como .NET 6-9. Esto garantiza la integración fluida de la redacción y las API relacionadas en aplicaciones .NET 10.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Versión: 2024.10 recién lanzado