Excel to PDF conversion gives incorrect result on Linux servers

I am saving a excel file to PDF format.
The PDF generates fine on Windows server but when generated on Linux servers using same code,
The PDF text goes out of alignment.

I am using the below code

String opFileName = file.getAbsolutePath();
Workbook wb = new Workbook(opFileName);
wb.save(sOutputFile, SaveFormat.PDF);

Linux_PDF.PNG (33.7 KB)
Windows_PDF.PNG (30.4 KB)

@abhishekckshinde,

Thanks for the the screenshots.

Well, it should work equally fine on both platforms/OS. I suspect it might be due to missing fonts issue. Please make sure all the fonts (especially used in your Excel spreadsheet(s)) are installed on your Linux server too as you already have on Windows. Your Linux machine does not have all the required fonts (used in the workbook) that are needed for rendering. Please collect all the required fonts from your Windows machine which is working and place them in some directory on Linux machine. Suppose, you have placed the fonts in /usr/temp/myFonts directory, then set the fonts folder as below.
e.g
Sample code:

String fontFolder="/usr/temp/myFonts";
//fontFolder = "C:/temp/myFonts";//This is for Windows <<<
FontConfigs.setFontFolder(fontFolder, true);

Please note, you must execute this code before you execute any other Aspose.Cells code. For more information, please see these articles in the section:

Hope, this helps a bit.

Hi,
Adding the fonts resolved major issues, but there is still thing which did not render correctly.
There is an image in my template which renders correctly in Windows but is not rendering correctly on linux.
Please have a look at the attached screenshot.
windows.png (39.1 KB)
Linux.png (62.6 KB)

@abhishekckshinde,

Thanks for the screenshots.

Seeing your images, it looks there are still some fonts missing (which needs to be installed and set) on your Linux machine. Please check all the fonts used in the workbook (on Windows machine) and then you must have and set all those fonts on Linux server. This topic will help you to get list of fonts used in the workbook via Aspose.Cells APIs:

If you still could not figure out your issue (even after installing and settings fonts folder path (in code)), please provide your template Excel file and output Pdfs (one on Windows and other on Linux), we will check it soon.

Also, we recommend you kindly give it a try to our latest version/fix: Aspose.Cells for Java v18.3.5 if it makes any difference:

@Amjad_Sahi
We have used Arial Narrow in The template, but in-spite of adding all the fonts to the directory,
it still picks msyi.ttf and simsunb.ttf.
Arial fonts are not picked in Linux.

@abhishekckshinde,

Did you try our latest version/fix: v18.3.6 as we suggested in our previous post?
Please first make sure that you have installed all the underlying fonts (used in the template file) on Linux system and your system’s fonts folder should be accessed easily by other applications including Aspose.Cells APIs (you should have at least read permissions to that directory).

If this still could not help, as requested earlier, kindly provide your template Excel file and output PDFs (one taken on Windows and other on Linux), we will check it soon.

@Amjad_Sahi

We Tried adding the Font in Linux server and The PDF is generated with Some minor formatting Issues.
But not I am facing another Issue when generating PDFs when excel has multiple sheets.
I am getting the below exception :

Summary

com.aspose.cells.CellsException: Index: 2, Size: 2
at com.aspose.cells.zbit.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at org.apache.jsp.Wbom.HDPrintSpec_jsp._jspService(HDPrint_jsp.java:248)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.matrixone.apps.domain.util.LicCheckFilter.doFilter(LicCheckFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.matrixone.servlet.CustomFilter.handleDefault(CustomFilter.java:157)
at com.matrixone.servlet.CustomFilter.doFilter(CustomFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.matrixone.servlet.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:173)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.matrixone.apps.domain.util.IECompatabilityFilter.doFilter(IECompatabilityFilter.java:38)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

@abhishekckshinde,

Please provide us your template Excel file, so we could try to reproduce the issue by converting the file to PDF file format in a simple console Java program on linux. After reproducing the issue, we will log a ticket and try to figure it out soon.

D201840502.zip (31.7 KB)

@Amjad_Sahi

Please find the attached template.
Also, I would like this thread to be private. Could you please change it to Private if it is Pubic?

@abhishekckshinde,

Thanks for the template file.

I did test your scenario/case in linux (Ubuntu OS). I did convert your file to PDF file format, it works fine and I do not see any exception what so ever. I am using Aspose.Cells for Java v18.4.x (latest version/fix). See the attached screenshot for your reference which clearly shows the Java program runs fine and generated the output PDF file fine. I have also attached the output PDF file for your reference.
out2.pdf (37.8 KB)
Screenshot from 2018-05-08 14-57-57.png (148.8 KB)