Articles in this section
Category / Section

How to redact PDF using C# and VB.NET

4 mins read

Redaction is the process of removing sensitive or unwanted content from a document. Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can redact text and images from the PDF document.

Steps to redact PDF programmatically:

  1. Create a new C# console application project. Create a console application project

Create new console application
  2. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org. NuGet reference

Install nuget packages
  3. Include the following namespaces in the Program.cs file.

C#

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

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Pdf.Redaction
Imports System.Drawing

 

  1. Use the following code snippet to redact PDF document.

C#

// Load an existing PDF document PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf");

// Get the first page from the document PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;

// Create PDF redaction for the page PdfRedaction redaction = new PdfRedaction(new RectangleF(475, 158, 60, 17), System.Drawing.Color.Black);

// Add redaction to the loaded page page.Redactions.Add(redaction);

// Save and close the PDF document document.Save("RedactedPDF.pdf"); document.Close(true);

// This will open the PDF file so the result will be seen in the default PDF viewer System.Diagnostics.Process.Start("RedactedPDF.pdf");

 

VB.NET

' Load an existing PDF document
Dim document As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")' Get the first page from the document
Dim page As PdfLoadedPage = TryCast(document.Pages(0), PdfLoadedPage)' Create PDF redaction for the page
Dim redaction As PdfRedaction = New PdfRedaction(New RectangleF(475, 158, 60, 17), System.Drawing.Color.Black)' Add redaction to the loaded page
page.Redactions.Add(redaction)' Save and close the PDF document
document.Save("RedactedPDF.pdf")
document.Close(True)' This will open the PDF file so the result will be seen in the default PDF viewer
System.Diagnostics.Process.Start("RedactedPDF.pdf")

A complete working sample can be downloaded from RedactionSample.zip.

By executing the program, you will get the PDF document as follows.

Output PDF screenshot

Take a moment to peruse the documentation, where you can find other options like display text, image, and pattern on the redacted area, fill color on the redacted area. Also, redact the PDF without drawing the fill color, appearance, and features like encrypt and decrypt PDF document and digitally sign a PDF file with code examples.

Refer here to explore the rich set of Syncfusion Essential PDF features.

An online sample link to redact PDF document.

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about How to create Excel exploded pie chart in C#, VB.NET.

You can refer to our PDF feature tour page to learn about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied