We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Excel to PDF conversion page width not consistent in c#

I am trying to convert an excel to PDF but the page format is not correct , width of converted pages are not consistent .
Code Block :

Workbook workbook = new Workbook(@“C:\Sample\ExcelTest_.xls”);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions ();

        pdfSaveOptions.AllColumnsInOnePagePerSheet = true;
                    
        workbook.Save(@"C:\Sample\ExcelTest01.pdf", pdfSaveOptions);

PFA attached excel AND Converted with PDF
dATA.zip (69.0 KB)

@vikram.singh.lpl,

Thanks for the sample code segment and template file.

Well, when you specify PdfSaveOptions.AllColumnsInOnePagePerSheet attrobite, it will adjust the data (in columns) on single page no matter if the page size is changed to accommodate it. For your requirements, please use FitToPages option of PageSetup instead, see the update code segment for your requirements for your reference:
e.g
Sample code:

Workbook workbook = new Workbook(@“C:\Sample\ExcelTest_.xls”);

```
 foreach (Worksheet wks in workbook.Worksheets)
            {
                wks.PageSetup.SetFitToPages(1, 1);
            }                    
        workbook.Save(@"C:\Sample\ExcelTest01.pdf");
```

Hope, this helps a bit.

Thanks for your prompt response.
But after using this code footer section moved to mid of the page.
Attached new converted fileExcelTest01.pdf (65.1 KB)

Please suggest.

@vikram.singh.lpl,

Thanks for the file.

I am afraid, there is no better way to cope with if you still want all the pages to be same sized yet the footer will be at the bottom. For your information, Aspose.Cells renders Excel file to PDF file format with same display as you see print preview of different sheets in MS Excel manually. Also, if you use Ms Excel to save the file (after fitting the pages tall/wide or using other PageSetup options) to PDF, you may end us the same output PDF file. I am afraid, I could not find any reliable option in MS Excel to accomplish your task (retaining all the pages’ size same). I guess you should use your original code (as per the first post) to render your file as the page sizes’ difference is not much.

In case, you still think this can be done in MS Excel (when taking the print preview of the sheets), kindly do provide your Excel file with all the details, we will check it soon.