I have a set of documents in which each have an unwanted page break and two empty paragraph breaks that follow it. I have found the sample code to remove the page breaks and that works great. However, I cannot seem to figure out how to remove the trailing paragraph breaks.
Can you help? Attached is a sample document.
My code (as you can see I tried to set RemoveEmptyParagraphs and execute a MailMerge, that didn't work):
foreach (FileInfo fi in diSourceDir.GetFiles("*.doc"))
{
Document langDoc = new Document(fi.FullName);
NodeCollection runs = langDoc.GetChildNodes(NodeType.Run, true);
foreach (Run run in runs)
{
while (run.Text.IndexOf(ControlChar.PageBreakChar) >= 0)
run.Text = run.Text.Remove(run.Text.IndexOf(ControlChar.PageBreakChar), 1);
}
//langDoc.MailMerge.RemoveEmptyParagraphs = true;
//DataTable dtFake = new DataTable();
//dtFake.Columns.Add("Col1");
//dtFake.Rows.Add("junk");
//dtFake.AcceptChanges();
//langDoc.MailMerge.Execute(dtFake);
langDoc.Save(txtChargeLanugageDir.Text + @"\Converted\" + fi.Name);
}