public void JoinRunsWithSameFormatting()
{
//ExStart
//ExFor:Document.JoinRunsWithSameFormatting
//ExSummary:Shows how to join runs in a document to reduce unneeded runs.
// Let's load this particular document. It contains a lot of content that has been edited many times.
// This means the document will most likely contain a large number of runs with duplicate formatting.
Document doc = new Document(MyDir + "Rendering.doc");
// This is for illustration purposes only, remember how many run nodes we had in the original document.
int runsBefore = doc.GetChildNodes(NodeType.Run, true).Count;
// Join runs with the same formatting. This is useful to speed up processing and may also reduce redundant
// tags when exporting to HTML which will reduce the output file size.
int joinCount = doc.JoinRunsWithSameFormatting();
// This is for illustration purposes only, see how many runs are left after joining.
int runsAfter = doc.GetChildNodes(NodeType.Run, true).Count;
Console.WriteLine("Number of runs before:{0}, after:{1}, joined:{2}", runsBefore, runsAfter, joinCount);
// Save the optimized document to disk.
doc.Save(MyDir + @"\Artifacts\Document.JoinRunsWithSameFormatting.html");
//ExEnd
// Verify that runs were joined in the document.
Assert.Less(runsAfter, runsBefore);
Assert.AreNotEqual(0, joinCount);
}