This module uses the DevExpress Word Processing Document API to inspect and sanitize Word documents (remove sensitive or hidden content). You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Select hidden or invisible content to remove in the Remove Hidden Content section. Select sensitive content to remove in the Remove Sensitive Content section: Metadata, Comments, Custom XML Parts, ActiveX Content, Macros, OLE Objects, Track Changes.
Use available buttons to either produce a log on sensitive/hidden content or sanitize the document and download the result.
Select a Document
Sample.docx
Sanitize Settings
Hidden Text
Invisible Text
Metadata
Comments
Custom XML Parts
ActiveX Content
Macros
OLE Objects
Track Changes
using DevExpress.XtraRichEdit;
using DevExpress.Office;
using System.Text;
string InspectDocument(Stream inputStream, WordProcessingInspectOptions inspectOptions) {
using var richEditDocumentServer = new RichEditDocumentServer();
richEditDocumentServer.LoadDocument(inputStream);
StringBuilder output = new StringBuilder();
var inspectResult = richEditDocumentServer.Inspect(inspectOptions);
if(inspectResult.ContentTypes.Count == 0) {
output.AppendLine("No issues found.");
}
else {
output.AppendLine("Document contains the following hidden/sensitive content:");
output.AppendLine(string.Join(Environment.NewLine, inspectResult.ContentTypes));
}
return output.ToString();
}
Stream SanitizeDocument(Stream inputStream, DocumentFormat outputFormat, WordProcessingSanitizeOptions sanitizeOptions = null) {
using var richEditDocumentServer = new RichEditDocumentServer();
richEditDocumentServer.LoadDocument(inputStream);
// Inspect a document and create WordProcessingSanitizeOptions based on the inspection result
if(sanitizeOptions == null) {
var inspectResult = richEditDocumentServer.Inspect();
sanitizeOptions = inspectResult.CreateSanitizeOptions();
}
// Use the sanitizeResult object to get information about the removed content
var sanitizeResult = richEditDocumentServer.Sanitize(sanitizeOptions);
// Save document
var outputStream = new MemoryStream();
richEditDocumentServer.SaveDocument(outputStream, outputFormat);
outputStream.Position = 0;
return outputStream;
}