Excel to PDF converted file is very large

I am using aspose-cells version 8.4.2 to convert Excel to PDF. My code snippet is

// Load the document from disk.
Workbook workbook = new Workbook(sourceFile);

// Save the spreadsheet in PDF format.
workbook.save(destFile);

The xlsx file is 23MB, but the resulting PDF File is very large , almost 287 MB.
I’ve attached the source file for your reference.
I was unable to attach the converted file probably due to its size.

Please let me know how to resolve this issue.

Thanks.

Hi,


Thank you for contacting Aspose support.

We have evaluated your presented scenario while using the latest version of Aspose.Cells for Java 8.5.0.2 where the resultant PDF file is of 220MB. Please note, your provided spreadsheet has 11 worksheets where each worksheet contains almost 92000 rows. With such huge data set the resultant PDF file would also be large in size.

I am converted other formats with similar size source files but the resulting files are smaller:
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–>

File1.doc (23.7 MB) was converted to File1_doc.pdf (4.3 MB)

File2.txt (23.6 MB) was converted to File2_txt.pdf (5.1 MB)

Is there any options that can be set to get similar size for Excel to PDF Conversion? 23 MB to 220 MB seems to be excessive.

Thanks,


Hi,

ragrawal:
I am converted other formats with similar size source files but the resulting files are smaller:

File1.doc (23.7 MB) was converted to File1_doc.pdf (4.3 MB)

File2.txt (23.6 MB) was converted to File2_txt.pdf (5.1 MB)


Are you converting these files with Aspose APIs? If yes, please share the code as well as the samples. Please note, you may zip the files and upload them to any free file hosting services such as Dropbox/Google drive or your own server, and share the link here for us to download the samples.

ragrawal:

Is there any options that can be set to get similar size for Excel to PDF Conversion? 23 MB to 220 MB seems to be excessive.


You can cut down the number of pages for the resultant PDF by rendering one page per worksheet. While converting the spreadsheet to PDF with default settings, the API splits the data into pages as per paper type set in Page Setup of the worksheet. You can override this by setting the PdfSaveOptions.setOnePagePerSheet to true. As a result all contents of the worksheet will be squeezed on one PDF page and consequently the size of the file decreases. The following code generates a file of 122MB.

Java
Workbook book = new Workbook("D:/File1.xlsx"); PdfSaveOptions option = new PdfSaveOptions(); option.setOnePagePerSheet(true); book.save("D:/output.pdf", option);

Using Acrobat, the file size is only 15.1MB. Is it possible to mimic the setting in this PDF to see if the file size reduces in Aspose?
The Acrobat-converted file is attached for your reference.

Thanks

Hi,


Thank you for getting back.

We have logged an investigative ticket (CELLSJAVA-41415) in our database and have requested the product team to review your presented scenario to see if we can improve the size of resultant PDF. Please allow us some time to properly analyze the provided spreadsheet, and get back to you with updates in this regard.

Hi again,


We have noticed that your recently shared PDF file (generated with Adobe Acrobat) contains the data for only one worksheet. If you wish to achieve the same using Aspose.Cells APIs then it can produce smaller files than Adobe Acrobat. Please check the following code that generated one PDF file for each worksheet, and give it a try on your side. You will notice that each generated PDF is of 12 MB only. Moreover, if you uncomment the commented statements then the API will render each worksheet data on one page of the resultant PDF. In this case the resultant PDF files are of 8 MB in size.

Java

//Instantiate a new workbook
Workbook workbook = new Workbook(filePath);

//Get the count of the worksheets in the workbook
int sheetCount = workbook.getWorksheets().getCount();

//Make all sheets invisible except first worksheet
for (int i = 1; i < workbook.getWorksheets().getCount(); i++)
{
workbook.getWorksheets().get(i).setVisible(false);
}

//Initialize PdfSaveOptions for 1 PDF page per worksheet
// PdfSaveOptions options = new PdfSaveOptions();
// options.setOnePagePerSheet(true);

//Convert each worksheet to separate PDF
for (int j = 0; j < workbook.getWorksheets().getCount(); j++)
{
Worksheet ws = workbook.getWorksheets().get(j);
workbook.save(filePath + “_” + ws.getName() + “.pdf”/, options/);
if (j < workbook.getWorksheets().getCount() - 1)
{
workbook.getWorksheets().get(j + 1).setVisible(true);
workbook.getWorksheets().get(j).setVisible(false);
}
}