重新采样添加的图像 将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中呈现正确的值。