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

Free Support Forum - aspose.com

Remove empty pages from Word document using C#

Hi,

Is there any way I can know my current page(means through builder) is empty or all the paragraphs of the current page. And I want to remove the page if its empty. Can you please suggest a way for this.

@Gptrnt

In your case, we suggest you following solution.

  1. Please convert the Word document to PDF using Aspose.Words.
  2. Remove the empty pages from the PDF using Aspose.PDF.
  3. Convert PDF to DOCX using Aspose.PDF.

Below code example shows how to remove the empty pages from PDF.

Aspose.Pdf.Document inputDoc = new Aspose.Pdf.Document(MyDir + "input.pdf");
Aspose.Pdf.Document outputDoc = new Aspose.Pdf.Document();
foreach (var page in inputDoc.Pages)
{
    if (page.IsBlank(0.01d))
        continue;
    else
        outputDoc.Pages.Add(page);
}
outputDoc.Save("out.pdf");

Hi,

I want to find the current page is (where the builder is now) is empty or not. Not in the all document. And also i want the solution with word document.

@Gptrnt

In this case, we suggest you following solution.

  1. Move the cursor to the desired location.
  2. Get the page number of current node using LayoutCollector.GetStartPageIndex method.
  3. Iterate over nodes of document and get the nodes of specific page using GetStartPageIndex method.
  4. Delete the nodes of page if the text of node is empty or there is no Shape node.

Hope this helps you.

Hi ,
Is there a way to programmatically search and remove empty pages inside a document in java. I am bookmarking empty pages.At the end I am taking the bookmark collection with specific bookmark name. i just want to check these bookmarked page is empty or not.If empty, then they have to remove. Can you please suggest a way for that.

@Gptrnt

Could you please ZIP and attach your input and expected output documents? We will then provide you solution according to your requirement.