ExcelからPDFへの変換のための画像の再サンプリング
Contents
[
Hide
]
大きなMicrosoft Excelファイルに多くの画像が含まれている場合、出力PDFファイルのサイズを縮小し、全体的な変換性能を向上させるために画像の圧縮が必要になることがあります。Aspose.Cells は、追加された画像を再サンプリングして出力PDFファイルのサイズを縮小し、パフォーマンスを向上させることをサポートしています。
ExcelからPDFへの変換のための画像の再サンプリング
Aspose.Cells APIを使用してタスクを実行する方法を説明する以下のサンプルコードをご覧ください。この例では、Microsoft ExcelファイルをPDFファイルに変換しながら、ファイル内の画像を圧縮しています。
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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ResampleImagesforExceltoPDFConversion.class); | |
// Initialize a new Workbook | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Instantiate the PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Set Image Resample properties | |
pdfSaveOptions.setImageResample(300, 70); | |
// Save the PDF file | |
workbook.save(dataDir + "output.pdf", pdfSaveOptions); |
出力PDFのサイズを最小限に抑えるためにPdfSaveOptions.setImageResampleオプションを使用すると、画像の品質に若干影響を与える可能性があります。
スプレッドシートに数式が含まれている場合、PDF形式に変換する直前に Workbook.calculateFormula() を呼び出すことが最善です。これにより、数式に依存する値が再計算され、PDFで正しい値がレンダリングされます。