Excel to PDF - Paper Size and Stretching

I am creating an Excel spreadsheet using Apose.Cells. I set the format of the page to Legal Landscape, and I set a percentage to shrink the spreadsheet to fit the page exactly. Everything works fine. I'm now trying to convert this to a PDF, but the format is off. The spreadsheet doesn't fill the page like it does in Excel. Is there something that I need to set to get this to work?

Thanks,
-Damien

Hi Damien,

Which version do you use?

Please try the attached fix. If you still get this problem, please post your template file and created PDF file. We will check it soon.

I tried 4.5.0.31, same issue. Looking at the XML that is created, the column widths don't fill the Section.

<Section PageWidth="1008" PageHeight="612" PageMarginLeft="1.27cm" PageMarginRight="1.27cm" PageMarginTop="0.5cm" PageMarginBottom="0.5cm" IsUnicode="true" FontName="Tahoma" FontSize="5.36" xmlns="">

<Table VerticalAlignment="Center" ColumnWidths="2.7638 14.3212 111.3038 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662 23.3662">

The column widths only add up to only 782.6424. This may explain why when the PDF gets rendered, it isn't stretched the full width. Again, in Excel, everything is fine but in Excel it is.

In Excel, I'm setting the following:

sheet.PageSetup.Zoom = 67;
sheet.PageSetup.LeftMarginInch = .5;
sheet.PageSetup.RightMarginInch = .5;
sheet.PageSetup.TopMargin = .5;
sheet.PageSetup.BottomMargin = .5;
sheet.PageSetup.PaperSize = PaperSizeType.PaperLegal;
sheet.PageSetup.Orientation = PageOrientationType.Landscape;

I have attached the Excel file that I'm trying to convert. This is the sheet that I'm creating, but I have removed the data.

Thanks for your help with this.
-Damien

Hi,

Thanks for providing us the template excel file.

Well, when you convert xls2pdf, the attributes related page orientation and size (in excel file) will be documented and rendered with specific page width and height accordingly. So, there might be a subtle difference in the generated .pdf file if you talking about exact page size. Anyways, we will look into it and further improve it (to make it similar to xls) soon.

Thank you.

Hi Damien,

Please try this fix.

It's caused by Cells.GetColumnWidthPixel() does not return corret column width. We have fixed this bug.

I tried this DLL, but I still find the same result. The page is rendered only filling about 75% of the width of the PDF. I looked at the raw XML and found the columns widths to be exactly the same as before.

Thanks,
-Damien

Hi Damien,

We test this issue again.The columns widths are larger than before.

In the output xml with the current 4.5.1.0 version ,the total columns width is 890 pt,the margins width is 72 pt, the page width is 1008 pt. We will look into how to extend the total columns width as 936pt(1008- 72). It seems the displayed column width in the MS Excel is not same as the printed column width.

I'm still finding the same total width of 782.6424 when I do my testing and look at the XML using 4.5.1.0. 890 pt would at least be an improvement. I wonder why it's not working for me.

-Damien

Hi Damien,

Please remove all Aspose.Cells.dll files in your machine ,dowload the fix in the previous post,check this issue again. If you still get the same result,please creat a simple project and post it here. We will check it soon.The following is table option in xml file in my test project.

I managed to fix the PDF width by adjusting the zoom specifically for the PDF. Not the best solution, but it works.

I'm having another issue however. When converting to the PDF, I have a few instances where I'm using the SetRowHeight method. This works fine in Excel, but when converting to PDF, the row isn't as tall and some of the content overlaps into the cell below it. I've tried adjusting the row height to be even higher, but the problem still persists.

-Damien

Hi Damien,

Could you paste your sample code and post your template .xls, pdf files here. Kindly point out those instances related row heights too, we will check your issue soon.

Thank you.

The Excel file is the same one that I posted before, the row is #3.

As for the PDF, I'd rather not post it publicly. If you need a copy is there somewhere where I can send it?

-Damien

Hi Damien,

You have setted PageSetup.Zoom = 67.So the row #3 height in pdf is 63.75(In MS Excel) * 0.67 = 42.71.

In Excel, the zoom level is even lower, 54%, but when I print from Excel all is fine. I'm wondering why I'm not getting the same result as shown in Excel in the PDF. Initially I had the 54% zoom for both Excel and the PDF. The Excel sheet is fine, but with the PDF, the width was only about 75% of the page and the header column still was too short causing overlap with the text. I increased the PDF to 67%, which fixed the page width, but the header problem still persists.

-Damien

Note, I have tried bumping the header height to 100 for the PDF, but I still have the overlap problem. Could it be something with the bottom aligning of the text?

-Damien

I have attached a snapshot of the header problem. The overlap appears to be sporadic. On the first page it's only this column, the second page has more columns that do this, the 3rd page everything fits and so on. You can also see the amount of space above it has plenty of room to fit the text.

-Damien

Hi Damien,

Please post your adjust template file. We will check it soon.

If you do not want to see overlap, please use AutoFitColumns() .