Vermeiden Sie eine leere Seite in der Ausgabe PDF, wenn nichts zu drucken ist
Contents
[
Hide
]
Mögliche Nutzungsszenarien
Wenn die Excel-Datei leer ist und der Benutzer sie unter PDF mit Aspose.Cells speichert, wird in der Ausgabe PDF eine leere Seite gerendert. Manchmal ist dieses Standardverhalten unerwünscht. Aspose.Cells bietet diePdfSaveOptions.OutputBlankPageWhenNothingToPrint Eigenschaft, mit diesem Problem umzugehen. Wenn Sie es so einstellenFALSCH, dannCellsExceptiontritt immer dann auf, wenn in der Ausgabe PDF nichts zu drucken ist.
Vermeiden Sie eine leere Seite in der Ausgabe PDF, wenn nichts zu drucken ist
Der folgende Beispielcode erstellt eine leere Arbeitsmappe und speichert sie dann als Ausgabe PDF nach dem Festlegen vonPdfSaveOptions.OutputBlankPageWhenNothingToPrint Eigentum alsFALSCH. Da in der Ausgabe PDF nichts zu drucken ist, wird dieCellsExceptiongeschieht wie unten gezeigt.
Beispielcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)