当没有可打印的内容时,避免在输出 PDF 中出现空白页
Contents
[
Hide
]
可能的使用场景
当 Excel 文件为空并且用户使用 Aspose.Cells 将其保存到 PDF 时,它会在输出 PDF 中呈现空白页。有时,这种默认行为是不可取的。 Aspose.Cells 提供了PdfSaveOptions.OutputBlankPageWhenNothingToPrint财产来处理这个问题。如果你将它设置为错误的, 然后细胞异常只要输出 PDF 中没有可打印的内容,就会发生。
当没有可打印的内容时,避免在输出 PDF 中出现空白页
以下示例代码创建一个空工作簿,然后在设置后将其保存为输出 PDFPdfSaveOptions.OutputBlankPageWhenNothingToPrint财产作为错误的.由于输出 PDF 中没有要打印的内容,因此细胞异常发生如下所示。
示例代码
This file contains hidden or 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()); | |
} |
例外
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)