Free Support Forum -

How to remove blank pages in word files before appending them?

Hi Aspose,

I have 2 word templates used to fill dynamic data to bookmarks on them. After the necessary data filled to those templates, I will append the contents of them into a destination word file. However, I got an issue about blank page while appending those files.

In the template #1, I filled a table data to its bookmark and then saving this temp as another output file. The output file generated 2 pages. Page #1 contains the table data, page #2 is a blank page.
In the template #2, i filled the other dynamic data to its bookmark and saved it as another output file also.

After I have 2 output files, I will append the contents of them into a word file. However, the destination file still contains a blank page, which appears at the end of output file of template #1.

So, my question is: How to remove/clear all blank pages at the end of all output files before appending the contents of them into a destination file? I spent many times to research and find the solution on the internet and at Aspose site. Unfortunately, I cannot find any solutions to solve this issue. Pls help me to do this work.

Thanks so much for your help.

Hi ChienVH,

Thanks for your inquiry. Please note that MS Word documents are flow documents and there is no page concept in MS Word documents. Pages are created by MS Word on the fly and unfortunately there is no direct way to remove a Blank page.

You can try removing empty paragraphs from the end of your output documents. Please use the following code snippet to achieve your requirements. Hope this helps you.

<o:p> </o:p>

// Open template.<o:p></o:p>

Document doc = new Document(@“Test001\in.doc”);<o:p></o:p>

// Remove the empty paragraphs if necessary.<o:p></o:p>

while (!doc.LastSection.Body.LastParagraph.HasChildNodes)<o:p></o:p>


if (doc.LastSection.Body.LastParagraph.PreviousSibling != null &&<o:p></o:p>

doc.LastSection.Body.LastParagraph.PreviousSibling.NodeType !=NodeType.Paragraph)<o:p></o:p>



// If the current section becomes empty, we should remove it.<o:p></o:p>

if (!doc.LastSection.Body.HasChildNodes)<o:p></o:p>


// We should exit the loop if the document becomes empty.<o:p></o:p>

if (!doc.HasChildNodes)<o:p></o:p>



// Save output.<o:p></o:p>