Pdf | |
The PdfRedactionManager type exposes the following members.
| Name | Description | |
|---|---|---|
| PdfRedactionManager | Initializes a new instance of the PdfRedactionManager class. Call one of the Load overloads before marking areas. |
| Name | Description | |
|---|---|---|
| FillColor | Gets or sets the color that covers a redacted area, when the area is marked without a color of its own. The default is black. | |
| OverlayText | Gets or sets a text written in every redacted area, such as "[REDACTED]". The default is null: the areas are covered and nothing is written in them. | |
| OverlayTextColor | Gets or sets the color of OverlayText. The default is white. |
| Name | Description | |
|---|---|---|
| AddRedaction(Regex) | Marks every match of a regular expression, on every page, for redaction - for text that follows a pattern rather than a known value, such as account numbers or e-mail addresses. The matches are also taken out of what the document stores without showing it, as for a text. | |
| AddRedaction(Int32, RectangleF) | Marks a rectangle on a page for redaction, covered with FillColor. | |
| AddRedaction(Regex, Int32) | Marks every match of a regular expression on the given pages for redaction. With pageIndexesnull it is the same as the overload without pages, which also reaches what the document stores off its pages; with pages named, only those pages are changed. | |
| AddRedaction(Int32, RectangleF, PdfColor) | Marks a rectangle on a page for redaction, covered with the given color. | |
| AddRedaction(String, Boolean, Boolean) | Marks every occurrence of a text, on every page, for redaction. The text is also taken out of what the document stores without showing it - properties, metadata, bookmarks, annotation and form field text, attachments. | |
| AddRedaction(String, Boolean, Boolean, Int32) | Marks every occurrence of a text on the given pages for redaction. With pageIndexesnull it is the same as the overload without pages, which also reaches what the document stores off its pages; with pages named, only those pages are changed. | |
| Close | Closes the loaded document and releases its resources. | |
| GetDocument | Returns the redacted document as a new PdfDocument for further processing. Areas marked and not yet applied are applied first. | |
| Load(Byte) | Loads a PDF document from a byte array. | |
| Load(PdfDocument) | Loads an existing PdfDocument. | |
| Load(Stream) | Loads a PDF document from a stream. | |
| Load(String) | Loads a PDF document from a file. | |
| Load(Byte, String) | Loads a password-protected PDF document from a byte array. | |
| Load(PdfDocument, String) | Loads an existing password-protected PdfDocument. | |
| Load(Stream, String) | Loads a password-protected PDF document from a stream. | |
| Load(String, String) | Loads a password-protected PDF document from a file. | |
| Redact | Applies every area marked since the last call and returns what was redacted: one result per rectangle, including one per occurrence of each text. | |
| Save | Saves the redacted document and returns its bytes. Areas marked and not yet applied are applied first. | |
| Save(Stream) | Saves the redacted document to a stream. Areas marked and not yet applied are applied first. | |
| Save(String) | Saves the redacted document to a file. Areas marked and not yet applied are applied first. |
Mark areas with AddRedaction(Int32, RectangleF) (a rectangle on a page) or AddRedaction(String, Boolean, Boolean) (every occurrence of a text), apply them with Redact, then save the result with Save(String) or continue with GetDocument. Saving applies any area still waiting, so nothing marked is left unredacted.
What is removed. Text is removed glyph by glyph and the text around it keeps its position. A glyph is removed when the area covers its center, or a quarter or more of its width and of its height; a glyph the area only touches at its edge is kept. The part of an image inside the area is erased from the image data itself; an image that cannot be edited is removed whole. Links, annotations and form fields that touch the area are removed. Vector graphics inside the area are removed and those crossing it are covered.
Text found by search. A text is found wherever a page shows it, including the appearance of an annotation or a form field (which is then removed), and a phrase is found also when it continues on the next line, as one area per line. A text marked on every page is also taken out of what the document stores without showing it: the document properties and the XMP metadata, bookmark titles, the text of annotations and form fields, the alternate text of a tagged document, and attachments - their names and descriptions, and their content: an attached PDF is redacted in turn, a text file and the XML of an Office or OpenDocument file are edited, and any other attachment that contains the text is removed. Text drawn as an image (a scanned page) is not text: redact it by area.
Accessibility and archiving. The document keeps its logical structure, its PDF/UA declaration and its PDF/A level: the fill boxes are marked as artifacts and structure that pointed at removed links is taken out.
Signatures. Redacting changes the signed bytes, so a signature the document carried no longer verifies after the redaction. The document is written out whole, never appended to, so the removed content is not kept in an earlier revision of the file.
Coordinates are in points from the top-left corner of the visible page (its crop box), in the page's own orientation. On a page with a rotation the area turns with the page when it is displayed, as the content does.
PdfRedactionManager manager = new PdfRedactionManager(); manager.Load("contract.pdf"); manager.AddRedaction("ACME Corporation", false, true); manager.AddRedaction(0, new SelectPdf.Universal.Drawing.RectangleF(50, 700, 200, 40)); PdfRedactionResult[] results = manager.Redact(); manager.Save("contract-redacted.pdf"); manager.Close();