alexa

    Show / Hide Table of Contents

    Class PdfRedaction

    Represents a redactor for a loaded page.

    Inheritance
    System.Object
    PdfRedaction
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Syncfusion.Pdf.Redaction
    Assembly: Syncfusion.Pdf.Base.dll
    Syntax
    public class PdfRedaction
    Examples
     //Load the document.
     PdfLoadedDocument lDoc = new PdfLoadedDocument("input.pdf");
     //Get the first page from the document.
     PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;
     //Create a redaction object
     PdfRedaction redaction = new PdfRedaction(new RectangleF(40, 40, 50, 20));
     //Add redaction object into redaction collection of loaded page
     page.Redactions.Add(redaction);
     //Save and Close the document.
     lDoc.Save("sample.pdf");
     lDoc.Close(true);
    'Load the document.
    Dim lDoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
    //Create a redaction object
    Dim redaction As PdfRedaction = New PdfRedaction(New RectangleF(40, 40, 50, 20))
    //Add redaction object into collection
    page.Redactions.Add(redaction)
    'Save the document.
    lDoc.Save("sample.pdf")
    lDoc.Close(True)

    Constructors

    PdfRedaction(RectangleF)

    Initializes a new instance of the PdfRedaction class.

    Declaration
    public PdfRedaction(RectangleF bounds)
    Parameters
    Type Name Description
    System.Drawing.RectangleF bounds

    The rectangle bounds to be redact.

    PdfRedaction(RectangleF, Color)

    Initializes a new instance of the PdfRedaction class.

    Declaration
    public PdfRedaction(RectangleF bounds, Color fillColor)
    Parameters
    Type Name Description
    System.Drawing.RectangleF bounds

    The rectangle bounds to be redact.

    System.Drawing.Color fillColor

    The fill color on the redaction bounds.

    Properties

    Appearance

    Gets or sets the appearance on the redaction bounds (Read only).

    Declaration
    public PdfTemplate Appearance { get; }
    Property Value
    Type
    PdfTemplate
    Examples
     //Load the document.
     PdfLoadedDocument lDoc = new PdfLoadedDocument("input.pdf");
     //Get the first page from the document.
     PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;
     //Create a redaction object
     PdfRedaction redaction = new PdfRedaction(new RectangleF(40, 40, 100, 20));
     //Set appearance on the redaction bounds
     redaction.Appearance.Graphics.DrawString("Redacted", new PdfStandardFont(PdfFontFamily.Helvetica, 10), PdfBrushes.Black, PointF.Empty);
     //Add redaction object into redaction collection of loaded page
     page.Redactions.Add(redaction);
     //Save and Close the document.
     lDoc.Save("sample.pdf");
     lDoc.Close(true);
    'Load the document.
    Dim lDoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
    //Create a redaction object
    Dim redaction As PdfRedaction = New PdfRedaction(New RectangleF(40, 40, 100, 20))
    //Set appearance on the redaction bounds
    redaction.Appearance.Graphics.DrawString("Redacted", New PdfStandardFont(PdfFontFamily.Helvetica, 10), PdfBrushes.Black, PointF.Empty)
    //Add redaction object into collection
    page.Redactions.Add(redaction)
    'Save the document.
    lDoc.Save("sample.pdf")
    lDoc.Close(True)

    EnableExactBoundsMatch

    Enables precise redaction of text by matching the redaction bounds exactly to the character dimensions.

    Declaration
    public bool EnableExactBoundsMatch { get; set; }
    Property Value
    Type Description
    System.Boolean

    When set to true, this property ensure that only characters whose bounding boxes exactly match the specified redaction bounds are redacted; false otherwise. This allows for highly granular redaction, avoiding partial or unintended removal of adjacent text. It is especially useful when redacting individual characters or symbols with pixel-perfect accuracy.

    Remarks

    This property is effective only when TextOnly is also set to true. If the redaction bounds partially overlap a character, that character will not be redacted. Useful in scenarios requiring strict control over redacted content, such as legal or compliance documents.

    Examples
     //Load the document.
     PdfLoadedDocument lDoc = new PdfLoadedDocument("input.pdf");
     //Get the first page from the document.
     PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;
     //Create a redaction object
     PdfRedaction redaction = new PdfRedaction(new RectangleF(40, 40, 50, 20));
     //Set to redact text only
     redaction.TextOnly = true;
     //Enables precise redaction of text
     redaction.EnableExactBoundsMatch = true;
     //Set fill color for the redaction bounds
     redaction.FillColor = System.Drawing.Color.Green;
     //Add redaction object into redaction collection of loaded page
     page.Redactions.Add(redaction);
     //Save and Close the document.
     lDoc.Save("sample.pdf");
     lDoc.Close(true);
    'Load the document.
    Dim lDoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
    //Create a redaction object
    Dim redaction As PdfRedaction = New PdfRedaction(New RectangleF(40, 40, 50, 20))
    '//Set to redact text only
    redaction.TextOnly = true
    '//Enables precise redaction of text
    redaction.EnableExactBoundsMatch = true
    //Set fill color for the redaction bounds
    redaction.FillColor = Color.Green
    //Add redaction object into collection
    page.Redactions.Add(redaction)
    'Save the document.
    lDoc.Save("sample.pdf")
    lDoc.Close(True)

    FillColor

    Gets or sets the fill color on the redaction bounds (Read only).

    Declaration
    public Color FillColor { get; set; }
    Property Value
    Type
    System.Drawing.Color
    Examples
     //Load the document.
     PdfLoadedDocument lDoc = new PdfLoadedDocument("input.pdf");
     //Get the first page from the document.
     PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;
     //Create a redaction object
     PdfRedaction redaction = new PdfRedaction(new RectangleF(40, 40, 50, 20));
     //Set fill color for the redaction bounds
     redaction.FillColor = System.Drawing.Color.Green;
     //Add redaction object into redaction collection of loaded page
     page.Redactions.Add(redaction);
     //Save and Close the document.
     lDoc.Save("sample.pdf");
     lDoc.Close(true);
    'Load the document.
    Dim lDoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
    //Create a redaction object
    Dim redaction As PdfRedaction = New PdfRedaction(New RectangleF(40, 40, 50, 20))
    //Set fill color for the redaction bounds
    redaction.FillColor = Color.Green
    //Add redaction object into collection
    page.Redactions.Add(redaction)
    'Save the document.
    lDoc.Save("sample.pdf")
    lDoc.Close(True)

    TextOnly

    Gets or sets whether only the text within the redaction bounds should be redacted.

    Declaration
    public bool TextOnly { get; set; }
    Property Value
    Type
    System.Boolean
    Examples
     //Load the document.
     PdfLoadedDocument lDoc = new PdfLoadedDocument("input.pdf");
     //Get the first page from the document.
     PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;
     //Create a redaction object
     PdfRedaction redaction = new PdfRedaction(new RectangleF(40, 40, 50, 20));
     //Set to redact text only
     redaction.TextOnly = true;
     //Set fill color for the redaction bounds
     redaction.FillColor = System.Drawing.Color.Green;
     //Add redaction object into redaction collection of loaded page
     page.Redactions.Add(redaction);
     //Save and Close the document.
     lDoc.Save("sample.pdf");
     lDoc.Close(true);
    'Load the document.
    Dim lDoc As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
    //Create a redaction object
    Dim redaction As PdfRedaction = New PdfRedaction(New RectangleF(40, 40, 50, 20))
    '//Set to redact text only
    redaction.TextOnly = true
    //Set fill color for the redaction bounds
    redaction.FillColor = Color.Green
    //Add redaction object into collection
    page.Redactions.Add(redaction)
    'Save the document.
    lDoc.Save("sample.pdf")
    lDoc.Close(True)
    Back to top Generated by DocFX