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,
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);
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.
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,
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,
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,
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.