重新采样添加的图像 将Excel转换为PDF
Contents
[
Hide
]
在处理包含大量图像的大型Microsoft Excel文件时,您可能需要压缩已添加的图像,以减小输出PDF文件的大小并改善整体转换性能。Aspose.Cells for Python via .NET支持重新采样添加的图像以减小输出PDF文件的大小并在一定程度上改善性能。
请参阅以下示例代码,了解如何使用Aspose.Cells for Python via .NET 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
from aspose.cells import PdfSaveOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Initialize a new Workbook | |
# Open an Excel file | |
workbook = Workbook(dataDir + "input.xlsx") | |
# Instantiate the PdfSaveOptions | |
pdfSaveOptions = PdfSaveOptions() | |
# Set Image Resample properties | |
pdfSaveOptions.set_image_resample(300, 70) | |
# Save the PDF file | |
workbook.save(dataDir + "OutputFile_out_pdf", pdfSaveOptions) |
使用 PdfSaveOptions.set_image_resample 选项可使输出PDF的大小最小化,但可能会稍微影响图像质量。
如果您的电子表格包含公式,最好在将电子表格呈现为PDF格式之前调用 Workbook.calculate_formula()。这样做将确保重新计算依赖于公式的值,并在PDF中呈现正确的值。