出力PDFの空白ページを回避する

可能な使用シナリオ

Excelファイルが空で、そのファイルをAspose.CellsでPDFに保存すると、出力PDFに空白ページがレンダリングされます。このデフォルトの動作は望ましくない場合があります。Aspose.Cellsはこの問題に対処するために PdfSaveOptions.OutputBlankPageWhenNothingToPrint プロパティを提供します。これを false に設定すると、出力PDFに印刷する内容がない場合に CellsException が発生します。

出力PDFの空白ページを回避する

以下のサンプルコードは、空のワークブックを作成し、PdfSaveOptions.OutputBlankPageWhenNothingToPrint プロパティを false に設定して出力PDFとして保存します。出力PDFに印刷する内容がないため、以下の CellsException が発生します。

サンプルコード

// 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)