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

Free Support Forum - aspose.com

Query on deleting blank pages from a document

Hi,

I want to delete blank pages in a document but all these blank pages have footer information.

Can some one help me with this issue.

Thankyou...

Hi,

Thanks for your inquiry. Could you please attach your input document you want to remove blank pages from and expected Word document showing the correct behavior here for testing? You can use Microsoft Word to create your expected document. I will investigate the issue on my side and provide you code to achieve the same using Aspose.Words.

Best regards,

Hi,

Thanks for your reply. PFA the input and expected documents.

Here the requirement is to delete blank pages present in a section . And these blank pages are having footer text and watermark as well.

For instance the attatched input document has blank pages in section1, section 2, section 3 and all blank pages in all the three sections needed to be deleted.

Thank you.

Hi,


Thanks for the additional information. You can achieve this simply by removing the empty paragraphs from your document. Please see the following code:

Document doc = new
Document(@“C:\Temp\input.docx”);

foreach (Section sec in doc.Sections)

{

NodeCollection bodyParas = sec.Body.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph para in bodyParas)

if (!para.HasChildNodes)

para.Remove();

}

doc.Save(@"C:\Temp\out.docx");


I hope, this helps.

Best regards,

Hi,

Thanks for your reply.

I tried the code suggested by you but it is not working. It is not deleting empty paragraphs and so not deleting empty pages also.

It will be helpful if there is any other way to delete empty pages alone with out deleting empty paragraphs.

Kindly help me with this.

Hi,


Thanks for your inquiry. The Input.docx, you attached with this post, has 7 pages out of which 3 are completely blank. I have attached an output document out.docx here with this post which was generated by using the code from my previous post. You can see this document has 4 pages as expected.
SankarGanesh M:
I tried the code suggested by you but it is not working. It is not deleting empty paragraphs and so not deleting empty pages also.
Could you please attach your Word document you’re getting this problem with here for testing? We will investigate the issue on our end and provide you more information.

Best regards,

A post was split to a new topic: Remove blank empty pages from Word document