PDF scaling - distortion when saving a file as PDF for second time on Linux

We’ve encountered a strange issue with Aspose Cells 7.2.2 (and possibly earlier too). For some files saving as PDF for a second time distorts the PDF. But this only seems to occur on Linux, not Windows.

My test code is:

Workbook wb = new Workbook(file);
String out = file + “.Aspose.” + suffix;
wb.save(out, FileFormatType.PDF);
wb = new Workbook(file);
out = file + “.Aspose.b.” + suffix;
wb.save(out, FileFormatType.PDF);

For most files the 2 PDFs appear identical, but for one of our templates the second one is squashed. So far we’ve been unable to discover what makes this file behave differently.
I’ve attached the original file and the two PDFs.

We’re using Linux 2.6.18-308.4.1.el5

Any help would be appreciated.

Thanks.
Martin

Hi,


I was unable to reproduce the issue at my end with the latest version of Aspose.Cells for Java. Please have a look at the attached files. These files have been generated by using the latest version of Aspose.Cells for Java on my windows machine.

I have used following lines of code for this purpose:

String file = "D://scaling3.xls";
Workbook wb = new Workbook(file);
String out = file + ".Aspose1" + ".pdf";
wb.save(out, FileFormatType.PDF);
wb = new Workbook(file);
out = file + ".Aspose2" + ".pdf";
wb.save(out, FileFormatType.PDF);

Generally, the library should work the same regardless of OS. Can you confirm to us that you are using latest version of Aspose.Cells for Java? Meanwhile, we will update you with our findings on a linux system as well.

It works on my Windows machine too. But on our Linux servers it doesn’t, even though they’re running the same versions of Java and Aspose as my Windows machine.

Martin

Thanks Martin for your feedback.


We will look into this issue and let you know about any update ASAP. All these details have been forwarded to our development team to look into it and assist further.

The issue has been logged as: CELLSJAVA-40219.

Hi,

Please set the correct font path before creating the pdf. We have tested and found that setting font path can solve it.

How do I do that now? The examples I’ve found in this forum use book.getSaveOptions().setFontPath(), but that doesn’t seem to exist in recent versions of Aspose Cells. I’ve been looking through the online class docs but haven’t found anything yet.

Thanks.
Martin

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Please use CellsHelper.setFontDir(arg0) method to set the font directory for your pdf files.

Firstly, I’m now using Aspose-Cells 7.2.2.1, as that should fix a separate issue we’ve had.

Setting the font directory before saving the first PDF does make the 2 files the same, but they are now both wrong. It’s easier to see the problem with the sclaing4.xls I’ve attached to this post - it has a solid square at the top. When printing directly from Excel, or when I convert to PDF using Aspose Cells on Windows, this correctly appears square. But when I convert the file using Aspose Cells on linux it is compressed into a rectangle.

I’ve also noticed that it is correctly using fonts from the relevant font directory (/usr/share/fonts) even though CellsHelper,getFontDirs() doesn’t list that as one of the directories. Or does it use the “system default font directory” even if that isn’t specified?

Thanks.
Martin

Hi Martin,


Setting the font directory helps proper rendering of the excel file contents to PDF. From your feedback, it seems that setting font directory was the only thing missing. If it is not set explicitly, it uses the OS default font directory, as you can see from HERE.

As far as your issue of conversion to scaling4.xls is concerned, can you please provide us with your converted PDF files so that we can analyze them as supporting material to the issue. This will help us investigate into it and see if it’s some rendering issue.

I’ve attached scaling4.correct.PDF, which shows the square correctly. This was generated without setting the font directory.

scaling4.wrong.PDF shows the original square compressed to a rectangle. This was generated after setting the font directory.

Thanks.
Martin

Hi,


Thank you for the supporting PDF files. We will look into the issue and get back to you on this ASAP.

Hi,

We have tested your case and found the issue you said when giving an incorrect font path. If we give a correct font path(for your template file, at least there should be “Calibri” font in the specified path), we can get the correct result. So please make sure you have specified your correct font path.

For detecting default font path, it is hard for Java application to get the default font or font path of the system. Commonly we try to search some common font paths such as “c:\windows\fonts”. If no proper font can be found, we will try to use Arial font instead. Of course, without the correct font definition, it is very possible that the output is not same with what it should be.


I’m a bit confused about how this works, so I’ve been trying a test case. I’ve been using CellsHelper.getFontDir() and CellsHelper.getFontDirs(). Before I save a PDF these 2 methods both return nothing. After I save a PDF (without setting a font directory) then getFontDir() returns my JDK font directory, and getFontDirs() returns the JDK font directory followed by all the sub-directories in my linux /usr/share/fonts directory. I then call CellsHelper.setFontDir("/usr/share/fonts"), and after that getFontDir() and getFontDirs() both return just /usr/share/fonts.

However in all cases the PDF correctly contains embedded fonts from one of the sub-directories of /usr/share/fonts. So it seems to find fonts regardless of whether the font directory is set or what it is set to.

Hi,


Thanks for sharing your concerns.

We will provide you more details about the process on how it works.

We will get back to you soon.

thank you.

Hi,

To search the font path automatically, commonly we add the lib/fonts under javahome as one of the font dirs. And for sun’s JDK of 1.5/1.6, we try to use the FontManager to get some other font paths.

However this depends on special JDK vendor and version and system settings. Sometimes those automatically detected font paths take effect(required fonts can be found under them) and user need not to write additional code for rendering. But if user know those font paths used for their application, it is better to set them explicitly so that your application can give correct result always.