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 utilizzando Aspose.Cells, viene visualizzata una pagina vuota nel PDF di output. A volte, questo comportamento predefinito non è desiderato. Aspose.Cells fornisce la proprietà PdfSaveOptions.OutputBlankPageWhenNothingToPrint per gestire questo problema. Se la si imposta su false, allora si verificherà CellsException quando non c’è nulla da stampare nel PDF di output.
Evitare Pagina Vuota nel PDF di Output quando non c’è Nulla da Stampare
Il seguente codice di esempio crea un foglio di calcolo vuoto e lo salva come PDF di output dopo aver impostato la proprietà PdfSaveOptions.OutputBlankPageWhenNothingToPrint come false. Poiché non c’è nulla da stampare nel PDF di output, si verifica l'CellsException come mostrato di seguito.
Codice di Esempio
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Create empty workbook. | |
Workbook wb = new Workbook(); | |
//Create Pdf save options. | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
//Default value of OutputBlankPageWhenNothingToPrint is true. | |
//Setting false means - Do not output blank page when there is nothing to print. | |
opts.setOutputBlankPageWhenNothingToPrint(false); | |
//Save workbook to Pdf format, it will throw exception because workbook has nothing to print. | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
try | |
{ | |
wb.save(baos, opts); | |
} | |
catch(Exception ex) | |
{ | |
System.out.println("Exception Message: " + ex.getMessage()); | |
} |
Eccezione
Exception in thread "main" com.aspose.cells.CellsException: There is nothing to output/print.
at com.aspose.cells.zcab.a(Unknown Source)
at com.aspose.cells.zcab.a(Unknown Source)
at com.aspose.cells.zcab.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)