画像のリサンプリングの追加 ExcelからPDFへの変換
Contents
[
Hide
]
大量の画像を含む大きなMicrosoft Excelファイルで作業する際に、追加された画像を圧縮して出力PDFファイルサイズを減らし、全体的な変換パフォーマンスを向上させる必要がある場合があります。 Aspose.Cellsは、追加された画像をリサンプリングして出力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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Initialize a new Workbook | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir+ "input.xlsx"); | |
// Instantiate the PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Set Image Resample properties | |
pdfSaveOptions.SetImageResample(300, 70); | |
// Save the PDF file | |
workbook.Save(dataDir+ "OutputFile_out_pdf", pdfSaveOptions); |
SetImageResampleオプションを使用すると、出力PDFのサイズを最小限に抑えることができますが、画質にわずかな影響を与える可能性があります。
スプレッドシートに数式が含まれている場合、PDF形式に変換する直前に Workbook.CalculateFormula() を呼び出すことが最善です。これにより、数式に依存する値が再計算され、PDFで正しい値がレンダリングされます。