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.

Veuillez noterOnce 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

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

Questions Fréquemment Posées

Comment puis-je expurger du texte dans un PDF en utilisant une requête POST ?

Vous pouvez expurger du texte dans un PDF en effectuant une requête POST au serveur IronSecureDoc avec le fichier PDF et les mots que vous souhaitez expurger. Le serveur traite la requête et renvoie un PDF avec le texte expurgé.

Quelles sont les étapes pour utiliser l'API d'IronSecureDoc pour l'expurgation de PDF ?

Pour utiliser l'API d'IronSecureDoc pour l'expurgation de PDF, vous devez d'abord télécharger et démarrer l'image Docker IronSecureDoc, tester l'API en utilisant Swagger, spécifier le texte à expurger, exécuter l'appel API, et enfin exporter le document PDF expurgé.

Comment puis-je tester l'API d'IronSecureDoc avant de l'utiliser en production ?

Vous pouvez tester l'API d'IronSecureDoc en utilisant Swagger en accédant à Swagger UI, qui vous permet d'utiliser les points de terminaison fournis pour simuler le processus d'expurgation.

Quels paramètres peuvent être personnalisés dans une requête d'expurgation de PDF ?

Dans une requête d'expurgation de PDF, vous pouvez personnaliser des paramètres tels que user_password, owner_password, specific_pages, draw_black_box, match_whole_word, match_case, overlay_text, save_as_pdfa, et save_as_pdfua pour une personnalisation plus poussée.

Comment puis-je exécuter une requête d'expurgation de PDF en utilisant curl ?

Pour exécuter une requête d'expurgation de PDF en utilisant curl, vous pouvez utiliser une commande POST de curl, en spécifiant les paramètres nécessaires et le chemin du fichier dans votre invite de commande.

Que dois-je faire si mon PDF est protégé par mot de passe lors de l'expurgation ?

Si votre PDF est protégé par mot de passe, vous devez inclure le user_password ou owner_password dans les paramètres optionnels pour vous assurer que le processus d'expurgation puisse accéder et modifier le document.

Quel est l'objectif du paramètre 'draw_black_box' dans l'expurgation de texte ?

Le paramètre 'draw_black_box' spécifie s'il faut couvrir le texte expurgé avec une boîte noire. Cette option est utile pour visualiser les zones expurgées et est activée par défaut.

Comment puis-je héberger IronSecureDoc localement à des fins d'expurgation ?

Vous pouvez héberger IronSecureDoc localement en suivant les tutoriels fournis pour divers systèmes d'exploitation comme Windows, Mac ou Linux, vous permettant de gérer le processus d'expurgation sur votre serveur local.

Est-il possible d'expurger des pages spécifiques dans un PDF ?

Oui, vous pouvez spécifier quelles pages expurger en utilisant le paramètre 'specific_pages', ce qui vous permet de cibler des zones particulières du document pour l'expurgation.

Puis-je superposer du texte sur les zones expurgées dans un PDF ?

Oui, vous pouvez superposer du texte sur les zones expurgées en utilisant le paramètre 'overlay_text', qui vous permet de remplacer le texte expurgé par un message ou un indicatif personnalisé.

IronSecureDoc est-il compatible avec .NET 10 et ses bibliothèques clientes ?

Oui, IronSecureDoc propose un client .NET via le package NuGet IronSoftware.SecureDoc.Client, compatible avec .NET 10 ainsi qu'avec les versions précédentes (.NET 6 à 9). Vous pouvez ainsi intégrer facilement la rédaction et les API associées dans vos applications .NET 10.

Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Version : 2024.10 vient de sortir