officefileapi-devexpress-dot-pdf-ead3d9cc.md
Contains members used to manage redaction annotations without access to their inner structure.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public class PdfRedactAnnotationFacade :
PdfMarkupAnnotationFacade
Public Class PdfRedactAnnotationFacade
Inherits PdfMarkupAnnotationFacade
The following members return PdfRedactAnnotationFacade objects:
Use the PdfPageFacade.AddRedactAnnotation method to create a redaction annotation. You can create an annotation in a single or multiple page areas.
The following code snippet searches for specific words and creates redaction annotations over them:
using DevExpress.Pdf;
PdfDocumentProcessor pdfProcessor = new PdfDocumentProcessor();
pdfProcessor.LoadDocument("..\\..\\Invoice.pdf");
PdfDocumentFacade documentFacade = pdfProcessor.DocumentFacade;
PdfTextSearchParameters searchParameters =
new PdfTextSearchParameters();
searchParameters.CaseSensitive = true;
searchParameters.WholeWords = true;
string[] search = new string[] { "Maria Anders", "030-0074321", "[email protected]" };
foreach (string word in search)
{
PdfTextSearchResults results = pdfProcessor.FindText(word, searchParameters);
// If the text is found, create an annotation
if (results.Status == PdfTextSearchStatus.Found) {
var pageIndex = results.Page.GetPageIndex();
PdfRedactAnnotationFacade redactAnnotation =
documentFacade.Pages[pageIndex].AddRedactAnnotation(results.Rectangles);
redactAnnotation.Author = "Jane Doe";
// Set the redaction annotation appearance
redactAnnotation.FontColor = new PdfRGBColor(0, 0, 0);
redactAnnotation.FillColor = new PdfRGBColor(1, 1, 1);
redactAnnotation.FontName = "Arial";
redactAnnotation.FontSize = 0; // Enables font auto-size
redactAnnotation.OverlayText = "Classified";
redactAnnotation.TextJustification = PdfTextJustification.Centered;
redactAnnotation.RepeatText = false;
}
}
// Save the document with the redaction annotation
// and send it for review
pdfProcessor.SaveDocument("output_to_review.pdf");
Imports DevExpress.Pdf
Private pdfProcessor As New PdfDocumentProcessor()
pdfProcessor.LoadDocument("..\..\Invoice.pdf")
Dim documentFacade As PdfDocumentFacade = pdfProcessor.DocumentFacade
Dim searchParameters As New PdfTextSearchParameters()
searchParameters.CaseSensitive = True
searchParameters.WholeWords = True
Dim search() As String = { "Maria Anders", "030-0074321", "[email protected]" }
For Each word As String In search
Dim results As PdfTextSearchResults = pdfProcessor.FindText(word, searchParameters)
' If the text is found, create an annotation
If results.Status = PdfTextSearchStatus.Found Then
Dim pageIndex = results.Page.GetPageIndex()
Dim redactAnnotation As PdfRedactAnnotationFacade = documentFacade.Pages(pageIndex).AddRedactAnnotation(results.Rectangles)
redactAnnotation.Author = "Jane Doe"
' Set the redaction annotation appearance
redactAnnotation.FontColor = New PdfRGBColor(0, 0, 0)
redactAnnotation.FillColor = New PdfRGBColor(1, 1, 1)
redactAnnotation.FontName = "Arial"
redactAnnotation.FontSize = 0 ' enables font auto-size
redactAnnotation.OverlayText = "Classified"
redactAnnotation.TextJustification = PdfTextJustification.Centered
redactAnnotation.RepeatText = False
End If
Next word
' Save the document with the redaction annotation
' and send it for review
pdfProcessor.SaveDocument("output_to_review.pdf")
The PdfPageFacade.Annotations property returns all page annotation properties. You can filter redaction annotation properties, cast them to the PdfRedactAnnotationFacade class, and use class properties to change annotation parameters.
using DevExpress.Pdf;
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
// Load a document
processor.LoadDocument("output_to_review.pdf");
// Access the first page properties
PdfPageFacade page = processor.DocumentFacade.Pages[0];
// Retrieve all redact annotations
var redactAnnotations = page.Annotations.Where
(annotation => annotation.Type == PdfAnnotationType.Redaction);
// Change annotation parameters
foreach (PdfRedactAnnotationFacade redaction in redactAnnotations)
{
redaction.OverlayText = "Redacted";
redaction.FillColor = new PdfRGBColor(1, 0.94, 0);
}
processor.SaveDocument("output_to_review.pdf");
}
Imports DevExpress.Pdf
Using processor As New PdfDocumentProcessor()
' Load a document
processor.LoadDocument("output_to_review.pdf")
' Access the first page properties
Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)
' Retrieve all redact annotations
Dim redactAnnotations = page.Annotations.Where(Function(annotation) annotation.Type = PdfAnnotationType.Redaction)
' Change annotation parameters
For Each redaction As PdfRedactAnnotationFacade In redactAnnotations
redaction.OverlayText = "Redacted"
redaction.FillColor = New PdfRGBColor(1, 0.94, 0)
Next redaction
processor.SaveDocument("output_to_review.pdf")
End Using
Call the PdfAnnotationFacade.Remove() method to remove an annotation.
The following code snippet removes all redaction annotations on the first page:
using DevExpress.Pdf;
using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
// Load a document
processor.LoadDocument("Invoice.pdf");
// Access the first page properties
PdfPageFacade page = processor.DocumentFacade.Pages[0];
// Retrieve all rubber stamps
var redactAnnotations = page.Annotations.Where
(annotation => annotation.Type == PdfAnnotationType.Redaction).ToList();
// Remove all rubber stamps
foreach (PdfRedactAnnotationFacade redaction in redactAnnotations)
{
redaction.Remove();
}
processor.SaveDocument("output_deleted.pdf");
}
Imports DevExpress.Pdf
Using processor As New PdfDocumentProcessor()
' Load a document
processor.LoadDocument("Invoice.pdf")
' Access the first page properties
Dim page As PdfPageFacade = processor.DocumentFacade.Pages(0)
' Retrieve all rubber stamps
Dim redactAnnotations = page.Annotations.Where(Function(annotation) annotation.Type = PdfAnnotationType.Redaction).ToList()
' Remove all rubber stamps
For Each redaction As PdfRedactAnnotationFacade In redactAnnotations
redaction.Remove()
Next redaction
processor.SaveDocument("output_deleted.pdf")
End Using
You can apply a single redaction annotation, annotations on a specific page or an entire document. The following methods are available:
Each method allows you to specify what content type to keep visible in the redaction area. Create the PdfClearContentOptions object, set one of the Clear... properties to false to specify the content type to keep visible, and pass this object as the Apply... method parameter. If the options parameter is not specified, all content is redacted.
When the annotation is applied, it is no longer can be obtained, edited or removed.
The following code snippet applies redaction annotations made by a specific author:
using DevExpress.Pdf;
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
processor.LoadDocument("output_to_review.pdf");
PdfDocumentFacade documentFacade = processor.DocumentFacade;
foreach (var page in documentFacade.Pages)
{
var redactionAnnotations = page.Annotations.Where(annotation => annotation.Type == PdfAnnotationType.Redaction).ToList();
foreach (PdfRedactAnnotationFacade annotation in redactionAnnotations)
{
if (annotation.Author == "Jane Doe")
annotation.Apply();
}
}
processor.SaveDocument("output_applied.pdf");
}
Using processor As New PdfDocumentProcessor()
Dim documentFacade As PdfDocumentFacade = processor.DocumentFacade
For Each page In documentFacade.Pages
Dim redactionAnnotations = page.Annotations.Where(Function(annotation) TypeOf annotation Is PdfRedactAnnotationFacade)
For Each annotation As PdfRedactAnnotationFacade In redactionAnnotations
' Apply redaction from a specific author
If annotation.Author = "Jane Doe" Then
annotation.Apply()
End If
Next annotation
Next page
End Using
Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfRedactAnnotationFacade
See Also