Leere Seite im Ausgabe PDF vermeiden, wenn nichts gedruckt werden soll
Mögliche Verwendungsszenarien
Wenn die Excel-Datei leer ist und der Benutzer sie mit Aspose.Cells für Python via .NET in PDF speichert, wird eine leere Seite im Ausgabepdf gerendert. Manchmal ist dieses Standardverhalten unerwünscht. Aspose.Cells für Python via .NET bietet die PdfSaveOptions.output_blank_page_when_nothing_to_print-Eigenschaft, um dieses Problem zu behandeln. Wenn Sie es auf false setzen, tritt CellsException auf, wenn im Ausgabepdf nichts zu drucken ist.
Leere Seite im Ausgabe-PDF vermeiden, wenn nichts gedruckt werden soll
Der folgende Beispielcode erstellt eine leere Arbeitsmappe und speichert sie dann als PDF, nachdem die Eigenschaft PdfSaveOptions.output_blank_page_when_nothing_to_print auf false gesetzt wurde. Da in der Ausgabedatei PDF nichts gedruckt werden soll, tritt die CellsException wie unten gezeigt auf.
Beispielcode
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)) |
Ausnahme
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)