印刷するものが何もない場合、出力 PDF で空白ページを回避する
Contents
[
Hide
]
考えられる使用シナリオ
Excel ファイルが空で、ユーザーが Aspose.Cells を使用してそれを PDF に保存すると、出力 PDF で空白のページがレンダリングされます。このデフォルトの動作が望ましくない場合があります。 Aspose.Cells はPdfSaveOptions.OutputBlankPageWhenNothingToPrintこの問題に対処するプロパティ。として設定する場合間違い、 それからCellsException出力PDFに印刷するものがない場合は常に発生します。
印刷するものが何もない場合、出力 PDF で空白ページを回避する
次のサンプル コードでは、空のワークブックを作成し、設定後に出力 PDF として保存します。PdfSaveOptions.OutputBlankPageWhenNothingToPrintプロパティとして間違い.出力 PDF には何も出力されないため、CellsException下図のように発生します。
サンプルコード
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()); | |
} |
例外
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)