Back to Devexpress

PdfPageFacade.AddRedactAnnotation(IEnumerable<PdfOrientedRectangle>, Boolean) Method

officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-addredactannotation-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-pdf-dot-pdforientedrectangle-system-dot-boolean-x29.md

latest5.5 KB
Original Source

PdfPageFacade.AddRedactAnnotation(IEnumerable<PdfOrientedRectangle>, Boolean) Method

Creates a redaction annotation at the specified page area. Allows you to specify whether to use the page coordinate system

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public PdfRedactAnnotationFacade AddRedactAnnotation(
    IEnumerable<PdfOrientedRectangle> rectangles,
    bool usePageCoordinateSystem = true
)
vb
Public Function AddRedactAnnotation(
    rectangles As IEnumerable(Of PdfOrientedRectangle),
    usePageCoordinateSystem As Boolean = True
) As PdfRedactAnnotationFacade

Parameters

NameTypeDescription
rectanglesIEnumerable<PdfOrientedRectangle>

A collection of rectangles that specify a page area where the annotation should be located.

|

Optional Parameters

NameTypeDefaultDescription
usePageCoordinateSystemBooleanTrue

true to use the page coordinate system; otherwise, false.

|

Returns

TypeDescription
PdfRedactAnnotationFacade

An object that contains redact annotation properties.

|

Example

The following code snippet searches for specific words and creates redaction annotations over them:

csharp
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");
vb
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")

See Also

PdfPageFacade Class

PdfPageFacade Members

DevExpress.Pdf Namespace