Thanks Stefan.
I found the same through some research and came up with the following code which does the trick. Hope this can help someone else too.
using System;
using System.IO;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
class Program
{
public static void MssUnhideAllFields(byte[] ssBinary_in, out byte[] ssBinary_out)
{
using (MemoryStream memoryStream = new MemoryStream(ssBinary_in))
{
using (WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream, true))
{
var mainPart = doc.MainDocumentPart;
var docBody = mainPart.Document.Body;
foreach (var run in docBody.Descendants())
{
var runProperties = run.RunProperties;
if (runProperties == null)
continue;
var vanishElement = runProperties.Vanish;
if (vanishElement != null)
{
// Remove the vanish element
runProperties.RemoveChild(vanishElement);
}
}
// Save the changes
mainPart.Document.Save();
}
// Get the modified document's content as a byte array
ssBinary_out = memoryStream.ToArray();
}
}
public static void Main(string[] args)
{
byte[] inputBinary = /* your binary data here */ ; // Replace with your binary document data
byte[] outputBinary;
MssUnhideAllFields(inputBinary, out outputBinary);
// Now you can use the outputBinary for further processing or output
}
}