Double-Check Content Using Redaction Annotation in PDFs with C# | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Double-Check Content Using Redaction Annotation in PDFs with C#

Double-Check Content Using Redaction Annotation in PDFs with C#

PDF documents are used for exchanging business data with confidential information such as financial account numbers, social security numbers, email addresses, phone numbers, and credit card information.

At times, we need to show a part of or a whole document without exposing the sensitive content or private information. In this case, we can use the redaction feature to safely, permanently remove confidential information from a PDF document.

By using redaction annotation, users can do:

  • Content identification: A user applies redaction annotations that indicate the content areas needing to be deleted. Before proceeding to the next step, the user can review, move, and redefine the annotations.
  • Content removal: In this process, the marked content is removed permanently and a mark is applied in the redacted area defined by the redaction annotation.

In this blog, we are going to cover the following topics:

Let’s get started!

Say goodbye to tedious PDF tasks and hello to effortless document processing with Syncfusion's PDF Library.

Mark text and images for redaction

In this step, we only mark the content that needs to be redacted. We can mark the text and image area in the PDF document using rectangle bounds.

The following code example shows the procedure to mark the content for redaction using the PdfRedactionAnnotation method.

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("invoice_merged.pdf");
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;

//Create redaction annotation.
PdfRedactionAnnotation redactionAnnotation1 = new PdfRedactionAnnotation();
//Assign the rectangle bounds.
redactionAnnotation1.Bounds = new System.Drawing.RectangleF(35, 393, 100, 20);
//Set inner color of the annotation.
redactionAnnotation1.InnerColor = Color.Black;
//Set border color of the annotation.
redactionAnnotation1.BorderColor = Color.Red;
//Add annotation to the page.
loadedPage.Annotations.Add(redactionAnnotation1);

PdfRedactionAnnotation redactionAnnotation2 = new PdfRedactionAnnotation();
redactionAnnotation2.Bounds = new System.Drawing.RectangleF(95, 435, 80, 100);
redactionAnnotation2.InnerColor = Color.Black;
redactionAnnotation2.BorderColor = Color.Red;

loadedPage.Annotations.Add(redactionAnnotation2);

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

By executing this code example, you will get a PDF document like the following screenshot.

Marking text and image for redaction
Marking text and image for redaction

Find text and mark with the redaction annotation

Using the find-text feature, you can find a particular text in a PDF document and mark that text using PdfRedactionAnnotation.

The following code example shows the procedure to find and mark text for redaction using PdfRedactionAnnotation.

// Load an existing PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Invoice.pdf");

TextSearchResultCollection searchCollection;

TextSearchItem text = new TextSearchItem("Invoice Number", TextSearchOptions.None);

//Search the text in PDF document.
loadedDocument.FindText(new List<TextSearchItem> { text }, out searchCollection);

//Iterate search collection to get search results.
foreach (KeyValuePair<int, MatchedItemCollection> textCollection in searchCollection)
{
//Get matched text collection.
foreach (MatchedItem textItem in textCollection.Value)
{
//Create redaction annotation.
PdfRedactionAnnotation redactionAnnotation1 = new PdfRedactionAnnotation();
//Assign the rectangle bounds to cover full invoice number.
redactionAnnotation1.Bounds =new RectangleF(textItem.Bounds.X,textItem.Bounds.Y,textItem.Bounds.Width+55,textItem.Bounds.Height);
//Set inner color of the annotation.
redactionAnnotation1.InnerColor = Color.Black;
//Set border color of the annotation.
redactionAnnotation1.BorderColor = Color.Red;
//Add annotation to the page.
loadedDocument.Pages[textCollection.Key].Annotations.Add(redactionAnnotation1);
}

}

loadedDocument.Save("Redact.pdf");
//Close the document.
loadedDocument.Close(true);

In the previous code example, we used the FindText method to find the invoice number in the PDF document. Then, we created the PdfRedactionAnnotation to mark the bounds we get from the FindText method.

By executing this code example, you will get a PDF document like in the following screenshot.

Find text and mark with the redaction annotation
Find text and mark with the redaction annotation

Unleash the full potential of Syncfusion's PDF Library! Explore our advanced resources and empower your apps with cutting-edge functionalities.

Mark page or consecutive pages for redaction

You can mark a whole PDF page for redaction using PdfRedactionAnnotation. You can also iterate each page of a PDF document and add the PdfRedactionAnnotation with the bounds of the page.

The following code example shows the procedure to find and mark a whole page for redaction using PdfRedactionAnnotation.

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Invoice.pdf");

//Iterate each page and add redaction annotation.
foreach (PdfLoadedPage page in loadedDocument.Pages)
{
//Create redaction annotation.
PdfRedactionAnnotation redactionAnnotation = new PdfRedactionAnnotation();
//Assign the page bounds to redaction annotation.
redactionAnnotation.Bounds = new System.Drawing.RectangleF(0, 0, page.Size.Width, page.Size.Height);
//Set inner color of the annotation.
redactionAnnotation.InnerColor = Color.Black;
//Set border color of the annotation.
redactionAnnotation.BorderColor = Color.Red;
//Add annotation to the page.
page.Annotations.Add(redactionAnnotation);
}

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

By executing this code example, you will get a PDF document like the following screenshot.

Marking consecutive pages for redaction
Marking consecutive pages for redaction

Change the look of redaction marks

You can set custom text and colors to a redaction annotation. This will help you provide the exact reason for the marked content, so anyone can easily review it and proceed further later.

The following code example shows the procedure to customize the appearance of redaction marks using the PdfRedactionAnnotation.

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Invoice.pdf");

//Create redaction annotation.
PdfRedactionAnnotation redactionAnnotation = new PdfRedactionAnnotation();
//Assign the page bounds to redaction annotation.
redactionAnnotation.Bounds = new System.Drawing.RectangleF(60, 150,170, 120);
//Set inner color of the annotation.
redactionAnnotation.InnerColor = Color.Black;
//Set border color of the annotation.
redactionAnnotation.BorderColor = Color.Red;

//Font for the overlay text.
redactionAnnotation.Font = new PdfStandardFont(PdfFontFamily.Courier, 10);
//Text color.
redactionAnnotation.TextColor = Color.White;
//Text alignment.
redactionAnnotation.TextAlignment = PdfTextAlignment.Center;
//Set overlay text.
redactionAnnotation.OverlayText = "Confidential";
//Set repeat text option.
redactionAnnotation.RepeatText = true;
//Enable appearance of the annotation.
redactionAnnotation.SetAppearance(true);

//Add annotation to the page page.Annotations.Add(redactionAnnotation);
loadedDocument.Pages[0].Annotations.Add(redactionAnnotation);

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

By executing this code example, you will get a PDF document like in the following screenshot.

Customizing the redaction marks
Customizing the redaction marks

See a world of document processing possibilities in Syncfusion's PDF Library as we unveil its features in interactive demonstrations.

Remove the marked content from PDF document

Finally, you can remove the sensitive content from a PDF document. It’s very easy; we just need to load each redaction annotation and then flatten it.

The following code example shows procedure to remove the marked content permanently by flattening the redaction annotation.

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("InvoiceMarked.pdf");

//Iterate each redaction annotation and apply flatten to redact marked content.
foreach(PdfAnnotation annotation in loadedDocument.Pages[0].Annotations)
{
if(annotation is PdfLoadedRedactionAnnotation)
{
(annotation as PdfLoadedRedactionAnnotation).Flatten = true;
}
}

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

By executing this code example, you will get a PDF document like in the following screenshot.

Removing the marked content from PDF
Removing the marked content from PDF

GitHub sample

You can download all these samples of PDF redaction annotation on GitHub repository.

Syncfusion’s high-performance PDF Library allows you to create PDF documents from scratch without Adobe dependencies.

Conclusion

In this blog post, we have learned how to use the PdfRedactionAnnotation method to mark content for redaction and then remove the content permanently. This will help you easily review sensitive data in a PDF document before redacting it.

Take a moment to peruse our documentation, where you’ll find other options and features, all with accompanying code examples.

If you have any questions about these features, please let us know in the comments below. You can also contact us through our support forum, Direct-Trac, or feedback portal. As always, we are happy to assist you!

If you like this article, we think you would also like the following articles about PDF Library:

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed