The Apryse Fall 2026 Release is Here: Explore What's New

Home

All Blogs

How to Redact a PDF in Python

Published May 14, 2025

Updated October 23, 2026

Read time

5 min

email
linkedIn
twitter
link

How to Redact a PDF in Python

Sanity Image

Garry Klooesterman

Senior Technical Content Creator

This post covers redacting PDFs with the Apryse Server SDK using Python 3 on Windows, Linux, and macOS. It does not cover browser-side redaction in WebViewer or other languages. For other languages or platforms, see the Server SDK get-started guide. For browser-side redaction, see Ensuring Irreversible Redaction: Avoiding Hidden Metadata Risks.

Sanity Image

To redact a PDF in Python, mark the regions or text to remove, then apply them with Redactor.Redact() from the Apryse Server SDK. Redaction is permanent: the content inside each region is destroyed, not hidden with clipping or image masks. Redaction is an add-on, so your license key needs the Redaction Package. The pdfredacttest sample shows the complete working flow.

Introduction

Copied to clipboard

Protecting sensitive information is critical in any business and when not done right, the consequences can be serious, including fraud, reputational risk, and even personal harm.

Regulations such as the Health Insurance Portability and Accountability Act (HIPAA) in the United States, or the Personal Information Protection and Electronic Documents Act (PIPEDA) in Canada define how personal information is to be handled, secured, and disclosed.

One way to protect sensitive information is through redaction, which has been used for centuries as an effective method of removing information that should not be shared. However, if inadequate tools or methods are used, this information can potentially still be accessed. To help ensure redaction is done right, an SDK can be used to automate the process.

In this blog, we’ll look at what redaction is, why it’s important, and how to redact information from a PDF using an SDK. In the example, we’ll use Python, but the Apryse SDK is also available for other languages and frameworks such as C#, Java, and more.

PDF Redaction and its Use Cases

Copied to clipboard

Removing sensitive information from a document is known as redaction. This allows for the sharing of select information while protecting other sensitive information. This could be as simple as a medical student in clinical practice removing any patient identification information from the x-rays in their presentation. Another example is a business logging all their sales receipts but removing the credit card information for their customers. Both scenarios allow for the tracking and sharing of important information while protecting other sensitive information that could be exploited.

These are just two of the many examples of how redaction can be used.

Redaction Methods

Copied to clipboard

Paper Documents 

Common methods of redaction for paper are using black marker or opaque tape to obscure the text before it is photocopied, which permanently removes any information that was to be protected.

Blog image

Figure 1 – An example of a redacted document.

For paper documents, these methods work well, but what about digital documents?

Digital Documents

Ensuring sensitive information is redacted properly and permanently in digital documents can be more difficult. As the use of digital documents increased, the need for redaction became more apparent. Various methods have been used, some not as effective as others. For example, changing the color of the text or background or covering the text with opaque blocks in an image layer are not effective ways to redact information. This can be seen in various examples in the media where these methods were used but the text intended to be redacted was able to be retrieved.

Information to be redacted can also exist in the document in areas such as comments, version history, or metadata.

The Redaction Process in Python

Copied to clipboard

The redaction process at a basic level consists of two main parts:

  • Identify the content to be redacted.
  • Remove the content.

It’s simple enough but it’s also important that the right tools or methods are used. Otherwise, sensitive information could be unintentionally released resulting in potentially severe consequences.

PDF Redaction Using Apryse SDK in Python

Copied to clipboard

There are several benefits to automating the redaction process. For example, using an SDK like the Apryse SDK to automate redaction helps:

  • Remove hidden content such as metadata, XML Forms Architecture (XFA) content, and Extensible Metadata Platform (XMP) content by pairing redaction with Sanitization.
  • Permanently remove text, images, and vector content inside each redaction region.
  • Process many documents in batch, sequentially, in threads, or across machines.
  • Automatically identify and redact specific types of information based on pattern and keyword detection.

Note: You can even customize the redaction techniques to meet your specific needs.

Using the Apryse SDK, the redaction process consists of two steps:

  • Content Identification: A user marks the content to be redacted using redact annotations.
  • Content Removal: The SDK applies the redactions and the information is removed from the identified regions.

Note: You can customize the style elements of the redaction overlay including color, text, font, border, transparency, and more.

How Do I Redact a PDF in Python?

Copied to clipboard

Redacting a PDF in Python takes two steps: mark the content to remove, then apply the redactions with Redactor.Redact().

Redaction is permanent and irreversible. Redactor.Redact() destroys text, image, and vector content inside each region. After you save the output, the removed content cannot be recovered. Redact a copy and keep the original.

  1. Install the Apryse Server SDK for Python 3. The legacy PDFNetPython3 package on public PyPI is no longer updated.
  2. Get a free trial key. Trial keys include all packages, and a production key needs the Redaction Package.
  3. Call PDFNet.Initialize("YOUR_APRYSE_LICENSE_KEY") once at startup, before any other SDK call.
pip3 install apryse-sdk --extra-index-url=https://pypi.apryse.com

We'll now look at how to redact parts of a PDF using the code from our pdfredacttest sample, just one of our many code samples available.

I've provided the code here as well for easy reference.

Here we'll take a closer look at the code and break it down.

The areas to redact are defined in the array vec, created using the code:

vec = VectorRedaction()

Each section or region of the page to be redacted is defined by its own array element, for example:

This line tells the SDK that we’re going to redact page 2 of the document, creating a rectangular section with the coordinates “30, 30, 450, 450”. The content in that area will be left untouched with the remainder of the page being permanently deleted, and you’ll see the words “Negative Redaction.”

The following code customizes the appearance of the redaction overlay:

app = Appearance()
app.RedactionOverlay = True
app.Border = False
app.ShowRedactedContentRegions = True

And here’s the line of code that runs the redaction based on the parameters that have been previously set:

Redact(input_path + "newsletter.pdf", output_path + "redacted.pdf", vec, app)

Congrats! You’ve redacted your first document!

How Do I Find and Redact PII by Pattern?

Copied to clipboard

Use search and redact to find PII by text string, regular expression, or wildcard pattern, then redact every match. Patterns such as SSNs and credit card numbers find the matching text across the document.

Text search or text extraction creates the redact annotations. Redactor.Redact() then applies them. Marked regions can be seen, moved, and redefined until you apply them, so review each match before you run the redaction. The search and redact guide covers the full workflow.

How Do I Verify Content Was Removed?

Copied to clipboard

Search the saved output file for the strings you redacted. A correct result returns no matches.

Redaction destroys the content inside each region, so text search and text extraction on the output find nothing from those regions. Check these four items before releasing a file:

  • Run the Server SDK search on the output with the same strings or patterns you used to find the content.
  • Confirm you redacted a copy and kept the original untouched.
  • Open the output and confirm an overlay appears at each marked region.
  • Check hidden content separately. Metadata, XFA, XMP, embedded scripts, form data, and hidden layers are removed by Sanitization, a separate Server SDK capability in the base license.

How Do I Redact Many PDFs at Once?

Copied to clipboard

Initialize PDFNet once at process startup, then redact each document in turn. Each Redactor.Redact() call works on one PDFDoc, and the SDK keeps no state between operations. You can run files sequentially, in threads, in separate processes, or across machines.

In threaded runs, give each worker its own document. Sharing one PDFDoc across threads without locking causes undefined behavior, including crashes. If threads must share a document, use the Lock and LockRead APIs described in the locking guide. See where to call initialize for the startup pattern.

What Do Developers Ask About Redacting PDFs in Python?

Copied to clipboard

How Do I Redact a PDF in Python?

Copied to clipboard

Mark the regions or text to remove, then apply them with Redactor.Redact() from the Apryse Server SDK. Redaction destroys the content inside each region and is permanent and irreversible once saved. Your license key needs the Redaction Package.

How Do I Find and Redact PII by Pattern?

Copied to clipboard

Use search and redact to find content by text string, regular expression, or wildcard pattern, such as SSNs and credit card numbers. Review the marked matches, then apply them with Redactor.Redact(). Marked regions can be moved or redefined until you apply them.

How Do I Verify Content Was Removed?

Copied to clipboard

Search the saved output for the strings you redacted. A correct result returns no matches. Check metadata and other hidden content separately, because that is Sanitization, a separate Server SDK capability.

How Do I Redact Many PDFs at Once?

Copied to clipboard

Initialize PDFNet once at startup, then redact each document in a loop or across workers. Give each thread its own document, or use the locking APIs when threads share one. The SDK keeps no state between operations, so you can run files sequentially, in threads, or across machines.

Does Redaction in Python Require a Separate License?

Copied to clipboard

Yes. Redaction is an add-on, and your license key needs the Redaction Package. Trial keys include all packages. Redaction ships in the base binary, so there is no separate module download.

Conclusion

Copied to clipboard

As we’ve just seen, redaction is straightforward and easy when using an SDK like the Apryse SDK. Automating the process helps ensure sensitive information is properly protected. Using the wrong or inadequate methods to redact information can have serious consequences including reputational damage, financial loss, and even personal harm.

Try it out for yourself with our free trial.

Get started now or contact our sales team for any questions. You can also check out our Discord community for support and discussions.