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