Resample Added Images - Excel to PDF Conversion
Contents
[
Hide
]
While working with big Microsoft Excel files with lots of images, you might need to compress images that have been added to reduce the output PDF file size and improve the overall conversion performance. Aspose.Cells for Python via .NET supports resampling added images to reduce the output PDF file size and improve the performance somewhat.
Please see the following sample code that describes how to perform the task using the Aspose.Cells for Python via .NET API. The example converts a Microsoft Excel file to a PDF file while compressing the images in the file.
This file contains hidden or 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) |
Using the the PdfSaveOptions.set_image_resample option minimizes the size of the output PDF but it may affect the image quality a bit.
If your spreadsheet contains formulas, it is best to call Workbook.calculate_formula() just before rendering the spreadsheet to PDF format. Doing so will ensure that the formula dependent values are recalculated, and the correct values are rendered in the PDF.