Hi,
Could you please help me on remove blank page appears at end of the document while using <<[ControlChar.PageBreak]>> option in aspose word template using C# code Linq reporting engine
Hi,
Could you please help me on remove blank page appears at end of the document while using <<[ControlChar.PageBreak]>> option in aspose word template using C# code Linq reporting engine
The blank page you see at the end of the generated document is caused by the <<[ControlChar.PageBreak]>> placeholder. When the template is processed, Aspose.Words replaces this placeholder with a page break. If the page break is the very last element in the document, Word treats it as the start of a new (empty) page, which results in the extra blank page.
ControlChar.PageBreak is a literal page‑break character. After the report engine substitutes the placeholder, the document ends with a page‑break node.// Example: add the placeholder only if the current section is not the last one
if (!isLastSection)
{
templateBuilder.Append("<<[ControlChar.PageBreak]>>");
}
// Load the generated document
var doc = new Aspose.Words.Document("output.docx");
// Get the last node in the body
var lastNode = doc.LastSection.Body.LastChild;
if (lastNode != null && lastNode.NodeType == Aspose.Words.NodeType.ControlChar)
{
var ctrl = (Aspose.Words.ControlChar)lastNode;
if (ctrl.Type == Aspose.Words.ControlCharType.PageBreak)
ctrl.Remove(); // removes the trailing page break
}
doc.Save("output_clean.docx");
doc.RemoveEmptyParagraphs(); // extension method available in Aspose.Words
SectionStart.NewPage or PageSetup.RestartPageNumbering that could force an extra page.doc.LastSection.PageSetup.SectionStart = Aspose.Words.SectionStart.Continuous;
If the problem persists after trying the steps above, capture a minimal reproducible example (template, code snippet, and Aspose.Words version) and share it with Aspose support for deeper investigation.
I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.
SDK version unclear — refer to the official release notes before applying this guidance.
@rose.thomas The question is already answered here:
https://forum.aspose.com/t/about-addition-of-blank-page-in-aspose-word-template-dynamically-using-linq-reporting-engine/321488/7