/// <summary> /// This method is used when for some reason files have non-standard extensions or if its format is supported, but not pre-configured. /// For instance, all kinds of plain text files (logs, dumps etc) could be opened with text processors like MS Word/Open Office. /// </summary> public static void WorkWithFileExtensions() { RedactorConfiguration config = RedactorConfiguration.GetInstance(); DocumentFormatConfiguration docxSettings = config.FindFormat(".docx"); docxSettings.ExtensionFilter = docxSettings.ExtensionFilter + ",.txt"; using (Document doc = Redactor.Load(Common.MapSourceFilePath(TextFilePath))) { // Here we can use document instance to perform redactions doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]"))); doc.Save(); } }
/// <summary> /// This method supports a new document format(txt), it implements a handler for it by inheriting from DocumentFormatInstance class /// </summary> public static void CreateCustomFileFormat() { var config = new DocumentFormatConfiguration() { ExtensionFilter = ".txt", DocumentType = typeof(PlainTextDocument) }; using (Document doc = Redactor.Load(Common.MapSourceFilePath(TextFilePath), new LoadOptions(config))) { // Here we can use document instance to perform redactions doc.RedactWith(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[personal]"))); // Save the document to "*_AnyText.*" (e.g. timestamp instead of "AnyText") in its file name without rasterization doc.Save(new SaveOptions(false, "AnyText")); } }
public override void Initialize(DocumentFormatConfiguration config) { }