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.

Hinweis: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'
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

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

Häufig gestellte Fragen

Wie kann ich Text in einem PDF mit einer POST-Anfrage schwärzen?

Sie können Text in einer PDF schwärzen, indem Sie eine POST-Anfrage an den IronSecureDoc-Server mit der PDF-Datei und den Wörtern, die Sie schwärzen möchten, senden. Der Server verarbeitet die Anfrage und gibt eine PDF mit geschwärztem Text zurück.

Welche Schritte sind erforderlich, um die IronSecureDoc-API für die Schwärzung von PDFs zu nutzen?

Um die IronSecureDoc-API für die Schwärzung von PDFs zu nutzen, sollten Sie zunächst das IronSecureDoc Docker-Image ziehen und starten, die API mit Swagger testen, den zu schwärzenden Text angeben, den API-Aufruf ausführen und schließlich das geschwärzte PDF-Dokument exportieren.

Wie kann ich die IronSecureDoc-API vor der Nutzung in der Produktion testen?

Sie können die IronSecureDoc-API mithilfe von Swagger testen, indem Sie auf die Swagger UI zugreifen, die Ihnen ermöglicht, die bereitgestellten Endpunkte zu verwenden, um den Schwärzungsprozess zu simulieren.

Welche Parameter können in einer PDF-Schwärzungsanfrage angepasst werden?

In einer PDF-Schwärzungsanfrage können Parameter wie user_password, owner_password, specific_pages, draw_black_box, match_whole_word, match_case, overlay_text, save_as_pdfa und save_as_pdfua für weitere Anpassungen angepasst werden.

Wie führe ich eine PDF-Schwärzungsanfrage mit curl aus?

Um eine PDF-Schwärzungsanfrage mit curl auszuführen, können Sie einen curl POST-Anfragebefehl verwenden, bei dem Sie die erforderlichen Parameter und den Dateipfad in Ihrer Eingabeaufforderung angeben.

Was soll ich tun, wenn mein PDF während der Schwärzung passwortgeschützt ist?

Wenn Ihr PDF passwortgeschützt ist, müssen Sie das Benutzerpasswort oder Eigentümerpasswort in den optionalen Parametern angeben, um sicherzustellen, dass der Schwärzungsprozess auf das Dokument zugreifen und es ändern kann.

Was ist der Zweck des 'draw_black_box'-Parameters bei der Textschwärzung?

Der 'draw_black_box'-Parameter gibt an, ob der geschwärzte Text mit einem schwarzen Kasten überdeckt werden soll. Diese Option ist nützlich zur Visualisierung der geschwärzten Bereiche und ist standardmäßig aktiviert.

Wie kann ich IronSecureDoc lokal für Schwärzungszwecke hosten?

Sie können IronSecureDoc lokal hosten, indem Sie den Tutorials für verschiedene Betriebssysteme wie Windows, Mac oder Linux folgen, sodass Sie den Schwärzungsprozess auf Ihrem lokalen Server verwalten können.

Ist es möglich, bestimmte Seiten in einem PDF zu schwärzen?

Ja, Sie können angeben, welche Seiten geschwärzt werden sollen, indem Sie den 'specific_pages'-Parameter verwenden, der es Ihnen ermöglicht, bestimmte Bereiche des Dokuments für die Schwärzung zu selektieren.

Kann ich Text in einem PDF auf geschwärzten Bereichen überlagern?

Ja, Sie können Text auf geschwärzten Bereichen überlagern, indem Sie den 'overlay_text'-Parameter verwenden, der es Ihnen erlaubt, den geschwärzten Text durch eine benutzerdefinierte Nachricht oder einen Platzhalter zu ersetzen.

Ist IronSecureDoc mit .NET 10 und seinen Clientbibliotheken kompatibel?

Ja, IronSecureDoc bietet einen .NET-Client über das NuGet-Paket IronSoftware.SecureDoc.Client an und ist neben früheren Versionen wie .NET 6–9 auch mit .NET 10 kompatibel. Dadurch lässt sich die Schwärzungsfunktion und zugehörige APIs nahtlos in .NET 10-Anwendungen integrieren.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen
Bereit anzufangen?
Version: 2024.10 gerade veröffentlicht