Redact annotation removes content from a PDF document that is not supposed to be shared. DsPdf provides RedactAnnotation class to enable users to mark and apply redact annotations to the PDF file.
RedactAnnotation class provides the following properties to set various options for the redact annotation:
Property | Description |
---|---|
UserName | Adds the user name to the text label in the title bar of the annotation’s pop-up window when the annotation is open and active. |
Subject | Adds the text representing the subject of the annotation. |
Contents | Adds the text to the annotation for display. |
RichText | Adds the text to the annotation for display in the pop-up window when opened. You can format this text using HTML tags. |
Color | Sets the annotation color, popup window color, line color, etc. |
Area | Adds the list of quadrilateral structures defining the annotation area. The coordinates of the quadrilaterals' points are relative to the upper left corner of the page's media box, with the Y (vertical) coordinates increasing from top to bottom. If not empty, these quadrilaterals denote the content region that is intended to be redacted. If this list is empty, the Rect entry denotes the content region that is intended to be redacted. |
MarkBorderColor | Sets the outline color used to highlight the annotation rectangle. |
MarkFillColor | Sets the color used to fill the annotation rectangle. |
Opacity | Sets the opacity of the annotation. |
OverlayFillColor | Sets the overlay fill color with which to fill the redacted region after the affected content has been removed. |
OverlayText | Sets the overlay text that should be drawn over the redacted region after the affected content has been removed. |
Justification | Sets the justification to be used in displaying the overlay text. |
OverlayTextRepeat | Sets a value indicating whether the text specified by OverlayText should be repeated to fill the redacted region after the affected content has been removed. |
PdfRect | Sets the rectangle that defines the location and size of the annotation on a page in PDF user space coordinates. The positive X axis extends horizontally to the right, and the positive Y axis extends vertically upward, with the origin usually in the lower left corner of the page. |
You can apply redact annotation in two phases:
When you mark the redact area, a marking or highlight appears in the place of content to show that the region has been marked for redaction. With DsPdf class library, you can find all instances of texts and mark the content for redaction. This allows anyone in charge for redaction to apply redactions on the marked content.
Refer to the following example code to mark a redact area in a PDF document:
C# |
Copy Code
|
---|---|
public void CreatePDF() { GcPdfDocument doc = new GcPdfDocument(); var fs = new FileStream(Path.Combine("TimeSheet.pdf"), FileMode.Open, FileAccess.Read); doc.Load(fs); //Load the document //Create Redact annotation RedactAnnotation redactAnnotation = new RedactAnnotation(); //search the text(e.g employee name) which needs to be redacted var l = doc.FindText(new FindTextParams("Jaime Smith", true, false), null); // add the text's fragment area to the annotation List<Quadrilateral> area = new List<Quadrilateral>(); area.Add(l[0].Bounds[0]); redactAnnotation.Area = area; redactAnnotation.Justification = VariableTextJustification.Centered; redactAnnotation.MarkBorderColor = Color.Black; //Add the redact annotation to the page doc.Pages[0].Annotations.Add(redactAnnotation); doc.Save("TimeSheet_Redacted.pdf"); } |
Once the areas in a PDF document are marked for redaction, redaction can be applied to those areas to remove the content from PDF documents. After the PDF content is redacted, it cannot be extracted, copied or pasted in other documents. However, you can add overlay text in the place of redacted content.
DsPdf allows you to apply redact to areas marked for redaction in PDF documents by using the Redact method of GcPdfDocument class. The Redact method has three overloads which provides you with the option to apply redaction to all the areas marked for redaction, to a particular area marked for redaction or a list of areas marked for redaction in a PDF document.
Refer to the following example code to apply redaction to a PDF document:
C# |
Copy Code
|
---|---|
var doc = new GcPdfDocument(); using (var fs = new FileStream(Path.Combine("Resources", "PDFs", "TimeSheet_Redacted.pdf"), FileMode.Open, FileAccess.Read)) { // Load the PDF containing redact annotations (areas marked for redaction) doc.Load(fs); //mark new redact area var rc = new RectangleF(280, 150, 100, 30); var redact = new RedactAnnotation() { PdfRect = rc, Page = doc.Pages[0], OverlayFillColor = Color.PaleGoldenrod, OverlayText = "REDACTED", OverlayTextRepeat = true }; // Apply all redacts (above redact and existing area marked for redaction) doc.Redact(); doc.Save(stream); return doc.Pages.Count; } |