Resampling Added Images - Excel to PDF Conversion with C++
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 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 API. The example converts a Microsoft Excel file to a PDF file while compressing the images in the file.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Initialize a new Workbook and open an Excel file
U16String inputPath = srcDir + u"input.xlsx";
Workbook workbook(inputPath);
// Instantiate the PdfSaveOptions
PdfSaveOptions pdfSaveOptions;
// Set Image Resample properties
pdfSaveOptions.SetImageResample(300, 70);
// Save the PDF file
U16String outputPath = outDir + u"OutputFile_out_pdf.pdf";
workbook.Save(outputPath, pdfSaveOptions);
std::cout << "PDF file saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Using the SetImageResample 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 CalculateFormula 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.