At the end of the Document object, use the remove blank page method.
example:
private void RemoveBlankPage(ref Document doc)
{
if (doc.LastSection != null)
{
if (doc.LastSection.LastChild != null)
{
var body = doc.LastSection.LastChild as Body;
if (body != null)
{
for (int i = body.ChildNodes.Count - 1; i >= 0; i--)
{
var node = body.ChildNodes[i];
if (!string.IsNullOrWhiteSpace(node.Range.Text))
{
var text = node.Range.Text;
text = text
.Replace(\"\\t\", \"\")
.Replace(\"\\", \"\")
.Replace(\"\\r\", \"\");
if (string.IsNullOrWhiteSpace(text))
{
body.ChildNodes.RemoveAt(i);
}
else
{
break;
}
}
else
{
body.ChildNodes.RemoveAt(i);
}
}
}
}
}
}
If your file has multiple blank pages belonging to Document object, you can use the form of traversing the nodes under the [doc.Sections] to remove the blank pages.