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

Free Support Forum - aspose.com

Convert Word DOCX to PDF and Programmatically Detect If PDF has Blank Pages | C# .NET

Hello Support,

In few situations we have encountered word document having mail fields (letters) converted into PDF document produces blank PDF file.
We want to catch it programtically and report back to user so that they are aware of the issue and follow work around to continue the flow.

Thanks,
Parthiban

@parthiban.natarajan,

Please compress the following resources into ZIP format and attach the .zip file here for testing:

  • A simplified source Word document containing the merge fields
  • Aspose.Words v21.8 generated blank PDF file showing the undesired behavior
  • Please also create a standalone simplified Console Application (source code without compilation errors) that helps us to reproduce this problem on our end and attach it here for our testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will then start investigation into your particular scenario and provide you more information.

Hi Hafeez,

Thank you for quick response.

I am looking to find code logic how to detect blank PDF file using Aspose library.

@parthiban.natarajan,

You can check if the resultant PDF will have some text content in it or not by using the following code:

Document doc = new Document("C:\\Temp\\Doc1.docx");

string text = doc.ToString(SaveFormat.Text).Trim();
if (string.IsNullOrEmpty(text))
{
    Console.WriteLine("document has no text. so we will not save to PDF");
}
else
{
    // save to PDF
    doc.Save("C:\\temp\\Word Converted to PDF.pdf");
}

Hi Hafeez,

Thank you for quick response. Can you please also give code for checking blank PDF file.

@parthiban.natarajan

You can check blank page of a PDF with the following code:

Document pdfDocument = new Document(dataDir + "Before.pdf");
foreach(Page page in pdfDocument.Pages)
{
    Console.WriteLine(page.Number + " is blank = " + page.IsBlank(0.01d));
}