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

Free Support Forum - aspose.com

Page count with PDF renderer vs. page count in resulting pdf

When I use a WorkboorRender based on an empty PDF (for example the one attached) I get a page count of 0. When I save to pdf, I get a pdf with one page.

This seems like a bug.

var workbook = new Workbook(file);

var pdfPageCount = new WorkbookRender(workbook, new ImageOrPrintOptions { SaveFormat = SaveFormat.Pdf }).PageCount; // == 0

workbook.Save(filename, new PdfSaveOptions { PageIndex = pageIndex, PageCount = length }); // == 1

PS: For WorkboorRender based on tiff the page count is also 0.


Thanks for the template file, sample code and details.

After an initial test, I observed the issue as you mentioned by converting your template file (having empty sheets) to PDF file format. I found when
rendering an empty Excel file to PDF, it still produces the file with
one blank page.


Sample code:

int length = 1;
int pageIndex = 0;
var workbook = new Workbook("e:\\test2\\Neu+Microsoft+Office+Excel-Arbeitsblatt.xlsx");

var pdfPageCount = new WorkbookRender(workbook, new ImageOrPrintOptions { SaveFormat = SaveFormat.Pdf }).PageCount; // == 0

workbook.Save("e:\\test2\\outNeu+Microsoft+Office+Excel-Arbeitsblatt1.pdf", new PdfSaveOptions { PageIndex = pageIndex, PageCount = length }); == 1

Moreover, using WorkboorRender for the empty spreadsheet, I get a page count of 0 which is Ok.

I have logged an investigation ticket with an id "CELLSNET-43345" for your issue. We will look into it if this is expected behavior or a bug which needs to be fixed.

Once we have any update on it, we will let you know here.

Thank you.


We have evaluated your issue further.
Well, firstly, when the Excel file with empty sheets is rendered, there is no pages at all. So the page count is always zero. Since a PDF or tiff format with no pages would not have been a valid or meaningful document (without a page), we add a blank page when there is no page. This is actually not a bug. Secondly, the PageCount property in PdfSaveOptions should be lager than zero when we add a blank page and render a blank page to the document to make sure its file format’s validity.

Hope, you understand now.

Thank you.

Well, I understand that you are doing this on purpose but I still believe it is a bug or wrong design in this case.

When I export a pdf from an empty sheet in Excel 2013, I get an error message and no PDF is created. This seems like the correct behavior. I would suggest to also take this route for API design: When a method cannot do its intended work because a precondition is not met, this method should throw an exception.

Generating a PDF requires content. Since the sheet does not contain any content, a precondition of the generation method is not met, therefore an exception should be thrown.

I understand that this would create backwards compatibility problems in your API, which, in my opinion, would be a valid reason to stay with the current behavior.


Thanks for providing further details.

Well, your detail makes sense. You are right, when we save this template file (having no content/ data in the sheets), MS Excel prompts an error and mention that there is no data or contents to be rendered or printed. I have logged your concerns against your logged ticket “CELLSNET-43345” into our database. we will check if we can do something similar to what Ms Excel does. We also need to check if some users are still interested in rendering the PDF file with blank page, then we might not do that.

We will check and update you.

Thank you.


We have evaluated your issue in detail. Well, to throw an exception action may cause backward compatibility problems in our API, so we do not plan to do it.

Thank you.