Free Support Forum - aspose.com

Excel(.xlsx) to PDF Conversion: Large no of columns

Hi, I am trying to convert Excel to Pdf using Aspose Cells. I have a file, which has 8 columns, when I am converting it, all the columns are getting stacked, and the pdf doesn’t look as expected after conversion. I understand pdf has limited page size, and it is not possible all the time to get the exact conversion. However, I would need the conversion to be correct for most of the files. Is it possible to set the configuration of converted PDF to make sure nothing goes beyond a page?


Methods I have already tried:
PdfSaveOptions pdfOptions = new PdfSaveOptions();
pdfOptions.getAllColumnsInOnePagePerSheet();
pdfOptions.getOnePagePerSheet();

But that doesn’t seems to be working. Please let me know, if there is something else we can do? For reference I am attaching Sample xlsx and converted pdf.
I have already had a look at following links, haven’t find any of them useful.

https://www.aspose.com/community/forums/thread/817444/xlsx-to-pdf-conversion-output-file-size-exceed.aspx

http://www.aspose.com/docs/display/cellsnet/Render+One+PDF+Page+Per+Excel+Worksheet+-+Excel+to+PDF+Conversion

Any help is much appreciated!

Hi,


Thanks for the sample files.

Well, Aspose.Cells renders PDF file based on what is shown in the print preview of sheets in MS Excel (MS Excel built-in renderer for PDF also renders the PDF file in the same way - you may confirm it in MS Excel). I also checked the print previews for some sheets and are almost same as per the the output PDF file. I think for your needs, you may try to set the page orientation to landscape and specify all columns on one page for the worksheet, see the sample code for your reference as I have tested it using your template Excel file and it gives better results if not the best:
e.g
Sample code:

//Load your excel file
Workbook wb = new Workbook(“AdeemSample.xlsx”);

for (int i = 0; i< wb.getWorksheets().getCount(); i++)
{

Worksheet ws = wb.getWorksheets().get(i);

//Set Page Orientation.
ws.getPageSetup().setOrientation(PageOrientationType.LANDSCAPE);

}

PdfSaveOptions options = new PdfSaveOptions(SaveFormat.PDF);
options.setAllColumnsInOnePagePerSheet(true);

//Save to output PDF file
wb.save(“out1.pdf”, options);

Hope, this helps a bit.

Thank you.

Thanks Amjad, This was helpful.

One quick question: Is it possible in Aspose to automatically adjust the page size according to corresponding page size in Excel? For example, consider page 1 of the original source file. In that the page extends a long way vertically. So is there a way to get the page size longer for that particular sheet to provide better readability to the user. Also, please let me know if there is a way to segregate between multiple tabs of Excel

Hi,


Well, Aspose.Cells follows MS Excel standards and specifications and cannot go beyond it. Aspose.Cells renders the Excel spreadsheet to PDF file format based on what is shown in the print previews of different worksheets (in the workbook). MS Excel built-in render also does the same as you may confirm this by re-saving your file as PDF file format in MS Excel manually. What do you mean by “Is it possible in Aspose to automatically adjust the page size according to corresponding page size in Excel”, could you elaborate it more with details? Well, you may select your desired Paper size (from the available Paper sizes list) and make use of other Page Setup attributes/options in MS Excel before rendering to PDF, please open the Page Setup dialog box for any worksheet for reference. You can specify each PageSetup or other printable options via Aspose.Cells APIs.

Thank you.
Thanks for your response.
What I mean is lets assume Tab1 in Excel has 100 rows and Tab2 has 200 rows. So what I want is for Tab2 is it possible to accommodate all the rows in a page, which is longer than usual? If not, then is there an option to fit all the rows in 1 page as well?
Hope this is clear.

Hi there,


Thank you for the explanation.

You can consider using the PdfSaveOptions.OnePagePerSheet property for your requirement. Please note, when the aforementioned property is set to true, the Aspose.Cells APIs tries to render all contents of a Worksheet to single PDF page. Moreover, please note that the predefined page sizes for the Worksheet will be ignored and page size will depend on the contents size.

Thank you! This is helpful.