Different PDF generated document widths

Hi,

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"));

conditionsWorkbook.Worksheets[0].PageSetup.PaperSize = PaperSizeType.PaperA4;
conditionsWorkbook.Worksheets[0].PageSetup.Zoom = 83;
conditionsWorkbook.Worksheets[0].PageSetup.LeftMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.RightMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.TopMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.BottomMargin = 0.5;
conditionsWorkbook.Worksheets[0].Name = "Bedingungen";

MemoryStream stream = new MemoryStream();
conditionsWorkbook.Save(Path.Combine(Environment.CurrentDirectory, "Result.pdf"), SaveFormat.Pdf);
conditionsWorkbook.Save(Path.Combine(Environment.CurrentDirectory, "Result.xlsx"), SaveFormat.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.




Hi Olga,


Thank you for contacting Aspose support.

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”);

conditionsWorkbook.Worksheets[0].PageSetup.PaperSize = PaperSizeType.PaperA4;
conditionsWorkbook.Worksheets[0].PageSetup.Zoom = 83;
conditionsWorkbook.Worksheets[0].PageSetup.LeftMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.RightMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.TopMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.BottomMargin = 0.5;
conditionsWorkbook.Worksheets[0].Name = “Bedingungen”;

conditionsWorkbook.Save(“D:/temp/Result.pdf”, SaveFormat.Pdf);
conditionsWorkbook.Save(“D:/temp/Result.xlsx”, SaveFormat.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.

Hi Babar,

I tried to use latest version of Aspose and remove obsolete Open method, but my problem is not fixed yet and I have the same result. Any ideas?

Hi Olga,


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.

  1. Operating System version
  2. Operating System Architecture (32bit/64bit)
  3. Target Framework
  4. 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;

conditionsWorkbook.Save(“D:/temp/Result.pdf”, options);

Let us know if this suffice your requirements,

Hi Babar,

babar.raza:
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.

Thank you!

Hi Olga,


Thank you for providing additional details.

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”.

Looking forward to you kind response.

Babar,

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.

Hi Olga,


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.

Hi Babar,

New pdf was attached. Generation was performed by this C# code

Workbook conditionsWorkbook = new Workbook(Path.Combine(Environment.CurrentDirectory, "Data", "Conditions.xlsx"));

conditionsWorkbook.Worksheets[0].PageSetup.PaperSize = PaperSizeType.PaperA4;
conditionsWorkbook.Worksheets[0].PageSetup.Zoom = 83;
conditionsWorkbook.Worksheets[0].PageSetup.LeftMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.RightMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.TopMargin = 0.5;
conditionsWorkbook.Worksheets[0].PageSetup.BottomMargin = 0.5;
conditionsWorkbook.Worksheets[0].Name = "Bedingungen";

conditionsWorkbook.Save(Path.Combine(Environment.CurrentDirectory, "Result.pdf"), SaveFormat.Pdf);
conditionsWorkbook.Save(Path.Combine(Environment.CurrentDirectory, "Result.xlsx"), SaveFormat.Xlsx);

Evaluation warning placed in the generated document. I didnt receive update of aspose subscription yet.




Hi Olga,


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.

Hi Babar,

Thank you!

Hi Olga,


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.

Let us know of your test result.

Hi Babar,

It works with our test app. Great, thank you!

We need some time for applying these changes on remote machine with Win Server 2003 for check this at whole application.

Hi Olga,


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.

Hi Babar,

Your solution fixed this problem on our production environment. Thank you!

Hi Olga,


It’s good to know that you are up & running again. Please feel free to contact us if you need our further assistance with Aspose APIs.