Create PDF from excel

In our project we are using Aspose Cells for Java to convert excel into PDF.
Problem we are facing is no matter how long excel it’s getting converted into 1 page PDF.
Basically we want excel content to split across multiple pages depending on page size instead of shrinking text and fitting into only one page PDF.

Please let us know what settings we can use to achieve this formatting while generating PDF from excel.

Hi,


Well, generally, Aspose.Cells renders PDF file (from Excel file or workbook) based on PageSetup settings or based on what is shown in print preview in MS Excel. You may check to open the Excel file into MS Excel manually and see the print preview of the sheet, you would see the content in one page.

For your needs, I think you may try to change or specify the PageSetup settings accordingly for your needs or do not use PageSetup options like FitToPageTall or FitToPagesWide options before rendering to PDF, etc., see the document for your reference:
http://www.aspose.com/docs/display/cellsjava/Setting+Page+Options


Sample code:

PageSetup pageSetup = worksheet.getPageSetup();
pageSetup.setFitToPagesTall(0);
pageSetup.setFitToPagesWide(0);

Thanks for reply we tried above settings but it’s not working in our case.

Just to explain workflow
1. We use template excel file
2. Populate data in excel file (create extra rows)
3. Save excel file as PDF

Do we need to set anything specific in PDF options?
PdfSaveOptions saveOption = new PdfSaveOptions();
saveOption.setCalculateFormula(true);
saveOption.setOnePagePerSheet(false);

Please let us know if we can try any other settings.

Hi,


Please provide us the template file with filled data here, we will check your issue and help you to sort it out for your requirements. Also provide your output PDF file by Aspose.Cells APIs. Moreover, provide you expected PDF file that you may manually create from MS Excel file. We will evaluate your issue soon.

Thank you.

Thanks for Reply.
We were able to generate multiple page PDF after adding Page Set Up attribute.
However in all cases it’s generating 2 Page PDF even though content can fit on one page.
Attached excel and PDF with this post.
Please review and let us know if any solution is available to resolve this issue.

Hi,

vgadewar:




.... it's generating 2 Page PDF even though content can fit on one page.
Attached excel and PDF with this post.
Please review and let us know if any solution is available to resolve this issue.



Well, as I told you before, by default, Aspose.Cells renders PDF file based on PageSetup settings or based on what is shown in print preview in MS Excel for the sheet(s). For confirmation, you may check to open the Excel file into your MS Excel manually and see the print preview of the sheet, you would see the content in two pages too. This is not an issue with the product by any means, because, the component renders to PDF format based on the print preview of MS Excel which it should (you may also try to convert the Excel file to PDF manually in MS Excel and will also see two pages for your contents.)

For your needs, I think you may try to specify PdfSaveOptions.setOnePagePerSheet(true) for your needs here.

PdfSaveOptions saveOption = new PdfSaveOptions();
saveOption.setOnePagePerSheet(true);
workbook.save(stringFileName, saveOptions);



Let us know if you still have any confusion or issue.

Thank you.