Skip to content

Instantly share code, notes, and snippets.

@aspose-words-gists
Created February 27, 2025 10:32
Aspose.Words for .NET. Remove hidden text from document using C#.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET.git.
Document doc = new Document(MyDir + "Remove hidden text.docx");
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
para.ParagraphBreakFont.Hidden = false;
foreach (Run run in para.GetChildNodes(NodeType.Run, true))
{
if (run.Font.Hidden)
run.Font.Hidden = false;
}
}
doc.Save(ArtifactsDir + "Remove hidden text - Aspose.Words.docx");
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET.git.
File.Copy(MyDir + "Remove hidden text.docx", ArtifactsDir + "Remove hidden text - OpenXML.docx", true);
using WordprocessingDocument doc = WordprocessingDocument.Open(ArtifactsDir + "Remove hidden text - OpenXML.docx", true);
foreach (Paragraph paragraph in doc.MainDocumentPart.Document.Body.Elements<Paragraph>())
{
// Iterate through all runs in the paragraph.
foreach (Run run in paragraph.Elements<Run>())
{
// Check if the run has properties
RunProperties runProperties = run.RunProperties;
if (runProperties != null)
{
// Check if the text is hidden.
Vanish hidden = runProperties.Elements<Vanish>().FirstOrDefault();
if (hidden != null)
// Remove the hidden property to unhide the text.
hidden.Remove();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment