We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Remove Blank Pages At the End of a Document

Hi,


I have a couple of documents that I update using Aspose words and after the update is finished there might be 1 or more blank pages at the end.

Could you tell me how to remove the blank pages from end of a document?

Thanks

Paul

Hi

Thanks for your inquiry. There is not page concept in MS Word documents. Pages are created by MS Word on the fly. But you can try removing empty paragraphs from the end of your document. This should help. Here is the code:

// Open template.

Document doc = new Document(@"Test001\in.doc");

// Remove the empty paragraphs if necessary.

while (!doc.LastSection.Body.LastParagraph.HasChildNodes)

{

if (doc.LastSection.Body.LastParagraph.PreviousSibling != null &&

doc.LastSection.Body.LastParagraph.PreviousSibling.NodeType != NodeType.Paragraph)

break;

doc.LastSection.Body.LastParagraph.Remove();

// If the current section becomes empty, we should remove it.

if (!doc.LastSection.Body.HasChildNodes)

doc.LastSection.Remove();

// We should exit the loop if the document becomes empty.

if (!doc.HasChildNodes)

break;

}

// Save output.

doc.Save(@"Test001\out.doc");

Hope this helps.

Best regards,