Remove blank empty pages from Word document

I have tried the same while converting doc to pdf, but its not working.Please find the below samples

sample: ws_1.zip (1.1 MB)

Please give a solution to remove blank pages without removing empty paragraphs.

Thanks in advance.

Its not removing the blank pages.I faced this issue while converting my doc to pdf. How to remove blank page without removing empty paragraphs.

Please find the below sample.
ws_1.zip (1.1 MB)

Thanks in advance.

@Gomathi

In your case, we suggest you following solutions. You can use one of them to achieve your requirement.

Solution 1:

  1. Split the document pages into separate document using PageSplitter utility. Please get the code of this utility from Github repository.
  2. Join the extracted documents except the ones that has no text. You can get the document’s text using Node.ToString(SaveFormat.Text) method and check either it is empty or not.

Solution 2:

  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");

I’am receiving an error(considering as empty page for the below samples). I’am using Latest Aspose word and pdf versions(19.6 & 19.5).Can you please tell me where the problem is with?

Samples:10NRXVCTHNF_10_blankPageIssue.zip (263.7 KB)

Thanks in advance.

Regards,
Gomathi.N

@Gomathi

Could you please share what error you are facing while using the shared code? We will investigate the issue and provide you more information on it.

Please find the code snippet for the same.

Logic:DocToPdf_Logic.zip (1.8 KB)

Thanks in advance.

Regards,
Gomathi.N

@Gomathi

Thanks for sharing the detail. We have converted the shared Word document to PDF using the latest version of Aspose.Words for Java 19.6 and remove the empty pages using the latest version of Aspose.PDF for Java 19.6. We have not found any issue with output PDF. Please check the attached output PDF. ws_1_WithoutBlankPages.pdf (468.0 KB)

Please use the following Java code to remove the empty pages from the PDF.

com.aspose.pdf.Document ip_pdfdoc = new com.aspose.pdf.Document("Test.pdf");
for(Page page :ip_pdfdoc.getPages()){
    if(page.isBlank(0.01d)){
        ip_pdfdoc.getPages().delete(page.getNumber());
    }
}
ip_pdfdoc.save("WithoutBlankPages.pdf");

Could you please share some detail what error you are facing while using Aspose APIs?

@tahir.manzoor

I had tried the same with latest 19.6 Aspose PDF and word versions & tried to convert just a word to PDF(The root cause of removing empty pages in PDF is with doc to PDF conversion, I guess).Please check with the below sample.

Sample:BlankpageIssues.zip (264.5 KB)

Thanks in advance.

Regards,
Gomathi. N

@Gomathi

Thanks for sharing the detail.

The input Word document has image shape and there is no image in it. When you convert your document to PDF using Aspose.Word, it generates the empty PDF file. No issue with this file.

When you remove empty page using Aspose.PDF from this PDF (Doc1.pdf) with following line of code, you get corrupted PDF.
ip_pdfdoc.getPages().delete(page.getNumber());

Please confirm if you are facing this issue. We will then log the issue accordingly in our issue tracking system.

Yeah this is the issue we are facing recently for some sort of files.How to convert the same into PDF in this case?

Thanks in advance.

Regards,
Gomathi N

1 Like

@Gomathi

About the final PDF showing error upon opening, this is expected behavior of the API. Aspose.PDF for Java API deletes any page which is blank and there is only one page which is already blank. Therefore, Aspose.PDF for Java API deletes it leaving the page collection as empty that causes error upon opening. So, if you do not want to delete the page when document contains only one blank page then you may use below code:

com.aspose.pdf.Document ip_pdfdoc = new com.aspose.pdf.Document("Test.pdf");
for(Page page :ip_pdfdoc.getPages()){
    if(page.isBlank(0.01d)){
        if(ip_pdfdoc.getPages().size() > 1){
        ip_pdfdoc.getPages().delete(page.getNumber());
        }
    }
}
ip_pdfdoc.save("WithoutBlankPages.pdf");

In case you have any further concerns then please feel free to contact us.

The above piece of code is to remove the blank page. But my issue is with DOC to PDF conversion.While converting a word to PDF, I’m getting empty PDF.But the word doc is having image content.Don’t consider on removing empty pages, do have concern on DOC to PDF conversion.Please check the same with above sample and code.

Thanks in advance.

Regards,
Gomathi.N.

1 Like

@Gomathi

Your input Word document does not has image. Please check the attached image for detail.

Please check the below sample.

Sample: Sample.zip (263.9 KB)

Regards,
Gomathi. N

1 Like

@Gomathi

We have logged this problem in our issue tracking system as WORDSNET-18818. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

1 Like

Dear Team,

Could you please fix the above issue as soon as possible as this is a very urgent requirement.
Thanks in advance

@Gomathi

We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

You reported this issue in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies

The issues you have found earlier (filed as WORDSNET-18818) have been fixed in this Aspose.Words for .NET 20.1 update and this Aspose.Words for Java 20.1 update.