Aspose.Cells PDF Generation

Right now I am using Aspose.Cells version 7.0.2. I am using this component to generate PDF. When I generate PDF in local machine, all the auto fit and text wrap is working properly.

But when I deploy the same piece of code in server and generate PDF from there, I can see text wrap is working fine but auto fit is not working properly. It seems, in server, Aspose.Cells is not able to determine the height of the row when it is mentioned as auto fit.

Attached is the sample PDF file generated from server.

I tried with the latest version of Aspose.Cells (i.e. 7.5). But still it is not working. I guess there is a bug in Asposer.Cells. So I need your assistance to resolve this issue.

Thanks,

Dip

Hi Dip,

Thank you for using Aspose products.

I am afraid, we are unable to evaluate your presented issue on our end due to the unavailability of your source code snippet and input template file. If you are using the .NET version of the product then we recommend you to give our latest fix version of Aspose.Cells for .NET v7.6.0.6 a try in your environment, and see if it makes any difference. In case the problem persists, please provide the runnable source code and template file along with the system details of your problematic server. We will quickly look into the issue for your.

Please also verify the following points on your end as they could have effected the rendering of PDF file,

  1. DPI settings of the server, e.g; it might be “Medium - 125%” or larger, whereas it should be set to “Smaller - 100% (default)”, under Control Panel => Appearance and Personalization => Display.
  2. Make sure that all the fonts used in the template file are installed on the server. Please also set the fonts directory explicitly by calling the CellsHelper.setFontDir(stringFontDirPath) method before making any calls to Aspose.Cells API.

Hi Babar,

Yes I am using the .NET version of this product. I just checked with the latest version of Aspose.Cells. Issue is still there. I checked fonts are installed properly in the server and DPI settings is also set to 100%.

Following the source code -

Workbook _workbook = new Workbook();

Worksheet _worksheet = _workbook.Worksheets[0];
_worksheet.Name = "Branch Archive Log";
_worksheet.IsGridlinesVisible = false;

Cells cells = _worksheet.Cells;

Style reportHeaderStyle = AsposeHelper.GetReportHeaderStyle();
Style reportTitleStyle = AsposeHelper.GetReportTitleStyle();
Style tableHeaderStyle = AsposeHelper.GetTableHeaderStyle();
Style tableBodyStyle = AsposeHelper.GetTableBodyStyle();

cells.Rows[0].Height = 75;

cells.Merge(1, 0, 1, 7);
cells[1, 0].SetStyle(reportHeaderStyle);
cells[1, 0].HtmlString = "Change Log for Archiving";
_worksheet.AutoFitRow(1);
cells.Rows[1].Height = 20;

cells.Merge(2, 0, 1, 6);
cells[4, 0].SetStyle(reportTitleStyle);
cells[4, 0].HtmlString = "Start Date " + startDate.ToShortDateString() + "     End Date " + endDate.ToShortDateString();
_worksheet.AutoFitRow(4);
cells.Rows[4].Height = 20;

cells[7, 0].SetStyle(tableHeaderStyle);
cells[7, 0].PutValue("POD Branch Id");
cells.Columns[0].Width = 20;

cells[7, 1].SetStyle(tableHeaderStyle);
cells[7, 1].PutValue("Change In");
cells.Columns[1].Width = 10;

cells[7, 2].SetStyle(tableHeaderStyle);
cells[7, 2].PutValue("Operation");
cells.Columns[2].Width = 10;

cells[7, 3].SetStyle(tableHeaderStyle);
cells[7, 3].PutValue("Property Name");
cells.Columns[3].Width = 15;

cells[7, 4].SetStyle(tableHeaderStyle);
cells[7, 4].PutValue("Old Value");
cells.Columns[4].Width = 24;

cells[7, 5].SetStyle(tableHeaderStyle);
cells[7, 5].PutValue("New Value");
cells.Columns[5].Width = 24;

cells[7, 6].SetStyle(tableHeaderStyle);
cells[7, 6].PutValue("Change Date");
cells.Columns[6].Width = 17;

_worksheet.AutoFitRow(7);

if (logs != null)
{
int rowCount = 8;
for (int count = 0; count < logs.Count; count++)
{
if (rowCount == 8)
{
tableBodyStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
cells[rowCount, 0].SetStyle(tableBodyStyle);
cells[rowCount, 0].HtmlString = string.IsNullOrEmpty(logs[count].BranchName) ? "" + logs[count].BranchId.ToString() + "" : "" + logs[count].BranchId.ToString() + "
(" + logs[count].BranchName + ")
";

cells[rowCount, 1].SetStyle(tableBodyStyle);
cells[rowCount, 1].PutValue(logs[count].TableName);
}
else
{
if (logs[count - 1].BranchId != logs[count].BranchId)
{
cells.Rows[rowCount].Height = 20;
rowCount = rowCount + 1;
tableBodyStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
cells[rowCount, 0].SetStyle(tableBodyStyle);
cells[rowCount, 0].HtmlString = string.IsNullOrEmpty(logs[count].BranchName) ? "" + logs[count].BranchId.ToString() + "" : "" + logs[count].BranchId.ToString() + "
(" + logs[count].BranchName + ")
";

tableBodyStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
cells[rowCount, 1].SetStyle(tableBodyStyle);
cells[rowCount, 1].PutValue(logs[count].TableName);
}
else
{
tableBodyStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.None;
cells[rowCount, 0].SetStyle(tableBodyStyle);

if (logs[count - 1].TableName != logs[count].TableName)
{
tableBodyStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
cells[rowCount, 1].SetStyle(tableBodyStyle);
cells[rowCount, 1].PutValue(logs[count].TableName);
}
else
{
tableBodyStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.None;
cells[rowCount, 0].SetStyle(tableBodyStyle);
}
}
}
tableBodyStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
cells[rowCount, 2].SetStyle(tableBodyStyle);
cells[rowCount, 2].PutValue(logs[count].Operation);

cells[rowCount, 3].SetStyle(tableBodyStyle);
cells[rowCount, 3].PutValue(logs[count].ColumnName);

cells[rowCount, 4].SetStyle(tableBodyStyle);
cells[rowCount, 4].PutValue(AsposeHelper.SplitAndMerge(logs[count].OldValue, 24));

cells[rowCount, 5].SetStyle(tableBodyStyle);
cells[rowCount, 5].PutValue(AsposeHelper.SplitAndMerge(logs[count].NewValue, 24));

cells[rowCount, 6].SetStyle(tableBodyStyle);
cells[rowCount, 6].PutValue(logs[count].ChangedDate.ToString());


_worksheet.AutoFitRow(rowCount);

/*
if (Convert.ToDecimal(cells.Rows[rowCount].Height.ToString().Length >= 5 ? cells.Rows[rowCount].Height.ToString().Substring(0, 5) : cells.Rows[rowCount].Height.ToString()) != 12.60M)
cells.Rows[rowCount].Height = cells.Rows[rowCount].Height + (cells.Rows[rowCount].Height * 33 / 100);

*/

rowCount++;
}
}

using (var _imgStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Ubs.LocationsDb.Content.Resources.ubs_regular_rgb.jpg"))
{
_worksheet.Pictures.Add(0, 0, ImageHelper.ResizeImgae(_imgStream, 28));
}
_worksheet.PageSetup.Orientation = PageOrientationType.Landscape;
_worksheet.PageSetup.CenterHorizontally = true;
_worksheet.PageSetup.PrintTitleRows = "$8:$8";
_worksheet.PageSetup.SetFooter(1, "Page &P of &N");
_worksheet.PageSetup.SetFooter(2, "Report produced on: " + DateTime.Today.ToString("dd MMMM yyyy") + " by " + SecurityManager.User.Identity);
_worksheet.PageSetup.LeftMarginInch = AsposeHelper.ConvertMMToInch(18);
_worksheet.PageSetup.RightMarginInch = AsposeHelper.ConvertMMToInch(18);
_worksheet.PageSetup.TopMarginInch = AsposeHelper.ConvertMMToInch(10);
_worksheet.PageSetup.BottomMarginInch = AsposeHelper.ConvertMMToInch(13);
_worksheet.PageSetup.FooterMarginInch = AsposeHelper.ConvertMMToInch(5);

MemoryStream stream = new MemoryStream();
_workbook.Save(stream, new PdfSaveOptions() { });
byte[] fileContent = stream.GetBuffer();
stream.Close();

Thanks,

Dip

Hi Dip,

Please note that we request runnable/compilable source code and template file in order to recreate the circumstances that could have triggered the problem on first place. Once we are able to replicate the issue on our end, we can quickly move forward to fix it for you.

By looking at your provided source code, it seems that you are creating the spreadsheet from scratch and rendering it to PDF. I have also noticed that your provided code is not compilable as you are using some helper methods that are not part of the provided code snippet. I can surly amend the code so that it could compile and produce a PDF file similar to the one desired, but I am not certain that if I will be able to replicate the presented issue after making the above said modifications. I would request you to provide a sample runnable application that could replicate the problem. Moreover, please provide the system details of your server such as Operating System, Service Pack version, Architecture (32 bit/64 bit), .NET Framework version and any other information you think would be helpful in identifying the problem cause.

Thank you for your cooperation and understanding.

Hi Babar,

Please find the attached source project. Due to data security, I had to change some information. But the auto fit issue is still there. I have also attached two pdf files. One was generated from local machine and another from server using the same piece of code. As the main project is built on MVC3, so I have also created the sample project on MVC3.

Server configuration -

Windows Server 2008 R2 Standard

Service Pack 1

64 bit operating system

Dot net framework version 4.0

Thanks,

Dip

Hi Dip,

Thank you for providing the sample application.

We have quickly tested the project on Windows 7 Home Premium 64 bit edition with Visual Studio 2013. PDF file generated in this environment does not have any formatting issues. Now we are moving forward to setup the environment as of your server so we could test the issue there as well. We will keep you posted with updates in this regard.

Hi Dip,

Thank you for your patience.

I have tested your provided project on Windows Server 2008 R2 Enterprise edition by freshly installing the operating system, service pack and Visual Studio 2013. I am afraid, I am unable to see any formatting issues in the resultant PDF (attached). Without making any changes to the source code, the results produced by the latest version 7.6.0.7 are the same as of your current component version. I am now preparing environment with Windows Server 2008 R2 Standard edition, and I will soon update you with my results.

I have uploaded the project including all the required binaries to this link for reference. You may download the project and execute it on your server to see if this makes any difference.

Hi Babar,

Thanks for your reply. This is really odd. I am not sure why you are not getting this formatting issue. Let’s try with the standard edition. But I am thinking what to do if the last try gets failed to reproduce.

Thanks,

Dipankar

Hi Dipankar,

Thank you for your response.

I have logged an investigative ticket (CELLSNET-42154) in our bug tracking system by attaching all relevant information so this issue could be discussed on a broader forum. We hope to replicate the issue with Windows Server 2008 R2 Standard edition, and therefore move forward to fix it in future releases of Aspose.Cells component.

Could you please provide the results of project shared earlier in my reply? Please note, the binaries included in the project were taken from Windows 7 Home Premium installation.

Hi Babar,

What results of project you need? Do you mean the PDF files? If it is PDF files, than those are attached here. One was generated from Dev Environment and another was generated from server.

For your information, this project was created in my development environment. Dev Environment details is attached as image.

After building the project, I deployed it into the Windows 2008 R2 server and got that formatting issue. The server details I have already shared with you earlier.

Thanks,

Dip

Hi Diparkar,

First of all, please accept our sincere apologies for your inconvenience.

Yes, we just needed the resultant PDF files for comparison purposes. Please note, I have already setup Windows Server 2008 R2 Standard edition on VM, and I am now moving forward to test the issue by deploying the application on IIS. I will shortly post back with my results for your reference.

Hi Babar,

Sorry for the late reply. Please find the attached file. This is the resultatnt pdf file which I want.

Thanks,

Dipankar

Hi Dipankar,

Thank you for providing the requested results for our comparison.

We have tested your presented scenario with different editions of Windows Server 2008 R2 (Standard/Enterprise) and Windows 7 (Home Premium/Ultimate) by freshly installing the operating system. As we have to test your provided project therefore the above said environments only contains Service Pack 1, Visual Studio 2013 and IIS7, among which Service Pack 1 came with the operating system where as Visual Studio 2013 was installed separately. IIS7 was pre-installed on Windows Server 2008 R2 (both editions) so we just had to configure it for deployment purposes.

All above discussed environments were unable to reproduce the issue of Auto Fit rows as exhibited in this file (comparing the first page for text cutout). Although we were able to identify some other formatting issues in our generated PDF files, such as Column “Change Date” is making the rows expand throughout the document and on Page-3, word “Logo Endorsement” isn’t properly formatted. Please check the attached output file and run a comparison of your own. We would also recommend that you should execute your sample project on your end in different environments and compare them as well with our provided files.

Note: We have already logged the test results to the ticket associated with this thread, and the development team is looking into this matter.

Hi Babar,

Thanks for the reply. But my actual issue was text cut out from bottom which was not reproduced. I dont know what will be my next step. But it was true that I got that issue while creating PDF which I shared already.

Thanks & regards,

Dipankar

Hi Dipankar,

Thank you for your response. We are in correspondence with the development team lead, and we are hoping to get updates in this regard from the development end. As soon as some news comes in, we will post here for your reference.

Please accept our sincere apologies for your inconvenience.

Hi again,

As narrated earlier, we are looking into the matter of
spreadsheet conversion to PDF for possible text formatting issues. We
have done everything we could to replicate the issue of text cut-out on our end but so
far we haven’t succeeded.

We have noticed that you are using “Frutiger 45 Light” font that is missing in Windows Server 2008 R2 installation. Could you please provide the said font from your development environment as well as production server for our review?

Hi Babar,

Please find the attached zip file. This contains the Frutiger font.

Thanks & regards,

Dipankar Haldar

Hi Dipankar,

Thank you for your prompt response and cooperation. We will keep you posted with updates in this regard.

Hi again,

We have been reviewing your presented issue on our end. We have noticed that the provided font is “Frutiger 45 Light Expert”, not “Frutiger 45 Light” which is being used in your project. We could have acquired the said font (Frutiger 45 Light) from any available source but in order to evaluate the difference in text formatting, the font file should come from your server. Please provide the font file from your development environment as well.

Thank you for your cooperation and understanding.

Hi Babar,

Please find the attached zip. These are from my development environment. Frutiger 45 Light must be within these.

Thanks,

Dipankar