PDF へのレンダリング中に、MS Excel ワークブックの外部リソースの読み込みを制御します

考えられる使用シナリオ

Excel ファイルには、リンクされた画像やオブジェクトなどの外部リソースが含まれている場合があります。 Excel ファイルを PDF に変換すると、Aspose.Cells はこれらの外部リソースを取得し、それらを PDF にレンダリングします。これを使用して行うことができますPdfSaveOptions.StreamProviderを実装するIStreamProviderインターフェース。

PDF へのレンダリング中に、MS Excel ワークブックの外部リソースの読み込みを制御します

次のサンプル コードは、PdfSaveOptions.StreamProvider外部リソースのロードを制御し、それらを操作します。を確認してくださいサンプル Excel ファイルコード内で使用され、出力 PDFコードによって生成されます。のスクリーンショット方法を示します古い外観イメージサンプル Excel ファイルの新しいイメージ出力 PDF で。

todo:画像_代替_文章

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Implement IStreamProvider
class MyStreamProvider implements IStreamProvider {
public void closeStream(StreamProviderOptions options) throws Exception {
System.out.println("-----Close Stream-----");
}
public void initStream(StreamProviderOptions options) throws Exception {
System.out.println("-----Init Stream-----");
// Read the new image in a memory stream and assign it to Stream property
File imgFile = new File( srcDir + "newPdfSaveOptions_StreamProvider.png");
byte[] bts = new byte[(int) imgFile.length()];
FileInputStream fin = new FileInputStream(imgFile);
fin.read(bts);
fin.close();
ByteArrayOutputStream baout = new ByteArrayOutputStream();
baout.write(bts);
baout.close();
options.setStream(baout);
}
}//MyStreamProvider
// ------------------------------------------------
// ------------------------------------------------
void Run() throws Exception {
// Load source Excel file containing external image
Workbook wb = new Workbook(srcDir + "samplePdfSaveOptions_StreamProvider.xlsx");
// Specify Pdf Save Options - Stream Provider
PdfSaveOptions opts = new PdfSaveOptions();
opts.setOnePagePerSheet(true);
opts.setStreamProvider(new MyStreamProvider());
// Save the workbook to Pdf
wb.save(outDir + "outputPdfSaveOptions_StreamProvider.pdf", opts);
}