Syncfusion Feedback

Redact PDFs in C# with .NET PDF Library

The Syncfusion® .NET PDF Library offers powerful capabilities for creating, reading, and editing PDF documents. Users can redact sensitive information in PDF documents, ensuring data privacy, security, and compliance with confidential-document handling standards.

Watch this video to see how to redact content in PDF documents using the Syncfusion .NET PDF Library.

Watch the video

Redact sensitive information from PDF documents in C#

Learn how to programmatically redact confidential text and images from PDF documents in C# using the Syncfusion .NET PDF Library. This guide demonstrates permanent content removal for data privacy compliance.

Step 1: Create a new C# Console Application project

Begin by creating a new C# Console Application project in Visual Studio or your preferred IDE to implement PDF redaction functionality.

Step 2: Install Syncfusion PDF Imaging NuGet package

Install the Syncfusion.Pdf.Imaging.Net.Core NuGet package in your C# project from NuGet.org. This package provides redaction and content removal APIs.

Step 3: Add required namespaces for PDF redaction

Import the following namespaces in your Program.cs file to access PDF redaction classes and area selection methods:

using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Redaction;

Step 4: Load the PDF document for redaction

Use the PdfLoadedDocument class to load your existing PDF file and retrieve the page where you want to redact sensitive information. This example signs the first page of the document.

//Load the PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")))
{
  // Get the first page of the document
  PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
}

Step 5: Define the redaction area

Create a PdfRedaction object with the area and fill color you want to remove, then add it to the page using AddRedaction to marks the region for redaction without removing the content yet.

Run

// Define a redaction area and set its color to black
PdfRedaction redaction = new PdfRedaction(new RectangleF(340, 120, 140, 20), Color.Black);
// Add the redaction to the page
loadedPage.AddRedaction(redaction);

Step 6: Apply redaction and save the document

Call the Redact method to permanently remove the marked content. Save the redacted PDF document with the sensitive information removed.

// Apply the redaction to remove content
loadedDocument.Redact();
// Save the PDF document
loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf"));

Get started quickly by downloading the installer and checking license information on the Downloads page.

Syncfusion .NET PDF Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.