If format is not supported, you will need to implement a handler for it by inheriting from DocumentFormatInstance class. Depending on the document’s features and required redactions, you will also need to implement one or several interfaces, allowing GroupDocs.Redaction to work with this document format.
Required to provide document general information and preview functionality
Each of these interfaces is optional, i.e. you don’t have to implement all of them, e.g. IImageFormatInstance - if you don’t need its functionality or IMetadataAccess, if your format does not support metadata.
Below, we create a DocumentFormatInstance class with custom logic for textual documents processing, supporting only textual redactions:
C#
publicclassCustomTextualDocument:DocumentFormatInstance,ITextualFormatInstance{privateRedactorSettingsSettings{get;set;}privateList<string>FileContent{get;set;}publicCustomTextualDocument(){FileContent=newList<string>();}publicoverridevoidInitialize(DocumentFormatConfigurationconfig,RedactorSettingssettings){Settings=settings;}publicoverridevoidLoad(System.IO.Streaminput){FileContent.Clear();using(varreader=newStreamReader(input)){while(!reader.EndOfStream){FileContent.Add(reader.ReadLine());}}}publicoverridevoidSave(System.IO.Streamoutput){varwriter=newStreamWriter(output);foreach(varlineinFileContent){writer.WriteLine(line);}writer.Flush();}publicRedactionResultReplaceText(Regexregex,Redactions.ReplacementOptionsoptions){try{if(options.ActionType!=Redactions.ReplacementType.ReplaceString){returnnewRedactionResult.Failed("This format allows only ReplaceString redactions!");}for(inti=0;i<FileContent.Count;i++){FileContent[i]=regex.Replace(FileContent[i],options.Replacement);}returnRedactionResult.Successful();}catch(Exceptionex){returnRedactionResult.Failed(ex.ToString());}}}
In order to use this class, we will need to add it to pre-configured formats, e.g. as a handler for dump files ("*.dump"):
Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to perform redactions for various document formats like PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Redaction App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.