Avoid Blank Page in Output PDF when there is Nothing to Print
Possible Usage Scenarios
When the Excel file is empty and the user saves it to PDF using Aspose.Cells for Python via .NET, it renders a blank page in output PDF. Sometimes, this default behavior is undesirable. Aspose.Cells for Python via .NET provides the PdfSaveOptions.output_blank_page_when_nothing_to_print property to deal with this issue. If you will set it as false, then CellsException will occur whenever there is nothing to print in the output PDF.
Avoid Blank Page in Output PDF when there is Nothing to Print
The following sample code creates an empty workbook and then saves it as PDF after setting the PdfSaveOptions.output_blank_page_when_nothing_to_print property as false. Since there is nothing to print in the output PDF, the CellsException occurs as shown below.
Sample Code
from aspose.cells import PdfSaveOptions, Workbook | |
from io import BytesIO | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create empty workbook. | |
wb = Workbook() | |
# Create Pdf save options. | |
opts = PdfSaveOptions() | |
# Default value of OutputBlankPageWhenNothingToPrint is true. | |
# Setting false means - Do not output blank page when there is nothing to print. | |
opts.output_blank_page_when_nothing_to_print = False | |
# Save workbook to Pdf format, it will throw exception because workbook has nothing to print. | |
ms = BytesIO() | |
try: | |
# Save to Pdf format. It will throw exception. | |
wb.save(ms, opts) | |
except Exception as ex: | |
print(str(ex)) |
Exception
Aspose.Cells.CellsException was unhandled
HResult=-2146232832
Message=There is nothing to output/print.
Source=Aspose.Cells
StackTrace:
at Aspose.Cells.Workbook.Save(String fileName, SaveOptions saveOptions)