I have created xlsx using Aspose Cells v.8.0.0.3 and I convert this document into pdf. It looks fine on my local machine, generated example attached (CorrectReport.xlsx and CorrectReport.pdf).
You can see listing of this generation below
Workbook conditionsWorkbook = new Workbook(); conditionsWorkbook.Open(Path.Combine(Environment.CurrentDirectory, "Data", "Conditions.xlsx"));
When I run this code on testing environment (without installed MS Excel, Visual Studio, etc) I received WrongReport documents, where xlsx doc is equal to CorrectReport, but pdf have different width with CorrectReport document.
How to generate pdf from excel sheet with the same page width?
AllColumnsInOnePagePerSheet is not working. Result the same as WrongReport.pdf. FitToPagesWide =1 lose font size and decrease it.
We have made a small change in your provided code snippet and tested it against the latest version of Aspose.Cells for .NET (Latest Version) . We are unable to observe the problem as stated in your original post. We would request you to please try the latest build on your side to see the difference in result.
C#
Workbook conditionsWorkbook = new Workbook(“D:/temp/Conditions.xlsx”);
Please note that Workbook.Open method was marked obsoleted sometime back. Now this method has been removed from the public API, so you should load the spreadsheet by passing the file path to the Workbook constructor as elaborated above.
We are sorry to know that the latest version didn’t help on your side. We need to thoroughly investigate the problem cause so please provide us the environment details as outlined below along with the PDF file generated on your end.
Operating System version
Operating System Architecture (32bit/64bit)
Target Framework
Complete source code (if it is different from what we have shared in previous post)
Just to confirm we are looking into right direction, the PDF (WrongReport.pdf) shared in your original post has two pages, where some contents of the worksheet have been cut out to force the generation of another page with leftover contents. The problem is not present in our shared PDF (output.pdf), could you please confirm this?
You can use the alternative approach as elaborated below by forcing the API to render all contents to one page of the PDF.
C#
Workbook conditionsWorkbook = new Workbook(“D:/temp/Conditions.xlsx”);
PdfSaveOptions options = new PdfSaveOptions();
options.OnePagePerSheet = true;
so please provide us the environment details as outlined below along with the PDF file generated on your end.
1. Windows Server 2003 R2 + SP2 2. 32bit 3. .NET 4.0 4. I cant share my source code. I think code listing from first post is enough - problem reproduces with shared code too.
babar.raza:
Just to confirm we are looking into right direction, the PDF (WrongReport.pdf) shared in your original post has two pages, where some contents of the worksheet have been cut out to force the generation of another page with leftover contents. The problem is not present in our shared PDF (output.pdf), could you please confirm this?
Yes, its so. One more detail. We can reproduce this bug only on machine with Windows Server 2003. Report generated on server with Windows Server 2012 OS is OK.
babar.raza:
You can use the alternative approach as elaborated below by forcing the API to render all contents to one page of the PDF.
No, I cant use this approach because of some sheets of my report should be rendered to multiply pdf pages.
We need some time to simulate your environment on our end to replicate the problem. We will keep you posted with updates in this regard. In the meanwhile, please share the problematic PDF generated on your end with this code snippet against the spreadsheet “Conditions.xlsx”.
Report generated by this code from Conditions.xlsx on Windows 7 attached in the first message as CorrectReport.pdf. Report generated on Windows Server 2003 attached as WrongReport.pdf at first message too.
All the PDF files attached in your original post were generated with obsoleted code segment and with an old release of the API. Please regenerate the report on Windows 2003 with latest version (link has been shared earlier) with updated code snippet, and share it here for investigation.
Thank you for your continues cooperation & understanding.
Thank you for the resultant PDF. We are currently setting up the required environment to test the case, and to isolate the problem cause. We will shortly get back to you with updates in this regard.
As discussed earlier that setting up the required environment may take some time, so we initiated an investigation in parallel so we could get hints of the the problem cause before actually testing it in a real environment. Upon further investigation we believe that the problem is more related to the missing fonts in the Windows Server 2003 rather than a bug in the API. Please note, the default font of the spreadsheet is Calibri, and Aspose.Cells API requires the default font (Calibir) to calculate the correct cell width and consequently the correct page break for rendering purposes. We have also discovered that Windows Server 2003 lacks this font (Calibri) by default.
We would request you to please perform a small test, that is; copy the Calibri font from your other installation to Windows Server 2003 font directory, and re-test the scenario. Hopefully it will produce the correct results.
Good to know that you are able to resolve the problem. Please take your time to apply the changes in your production application. Till then we will keep the case open.