Evitare Pagina Vuota nel PDF di Output quando non c è Nulla da Stampare
Possibili Scenari di Utilizzo
Quando il file Excel è vuoto e l’utente lo salva in PDF usando Aspose.Cells per Python via .NET, viene generata una pagina bianca nel PDF di output. A volte, questo comportamento predefinito è indesiderabile. Aspose.Cells per Python via .NET fornisce la proprietà PdfSaveOptions.output_blank_page_when_nothing_to_print per affrontare questo problema. Se la imposti su false, allora si verificherà CellsException ogni volta che non ci sarà nulla da stampare nel PDF di output.
Evitare Pagina Vuota nel PDF di Output quando non c’è Nulla da Stampare
Il codice di esempio seguente crea un foglio di lavoro vuoto e lo salva come PDF dopo aver impostato la proprietà PdfSaveOptions.output_blank_page_when_nothing_to_print su false. Poiché non c’è nulla da stampare nel PDF di output, si verifica CellsException come mostrato di seguito.
Codice di Esempio
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)) |
Eccezione
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)