Hi,
when converting the same Excel file with once on a Windows platform and once on a Linux platform, the results are different.
The result on Windwos seems correct, the one on Linux is completely blank.
The Excel file contains text in Calibri, a typical Windows font. I presumed that when a font was not installed on a system, like Calibri on Linux, it was substituted with some of the installed ones, thus producing a readable PDF.
What is the best way to avoid such problems and always obtain a readable, although perhaps not typographically correct PDF?
Hi Mario,
Hello,
I tried to follow your suggestion and specified a custom folder containing the fonts. However, when a font is not found there, Aspose.Cells seems to still check in the system fonts folder, even if it is not specified with CellsHelper.setFontDir(fontFolderPath).
How can I exclude the system fonts folder from the search path?
Hi Mario,
Workbook book = new Workbook(myDir + “input.xls”);
System.out.println(book.getDefaultStyle().getFont());
I tried the following code
public static void main(String[] args) throws Exception {
new com.aspose.cells.License().setLicense( the licence path );
CellsHelper.setFontDir( a folder containing some fonts );
FileOutputStream bout = new FileOutputStream( the path to the resulting PDF );
Workbook workbook = new Workbook(new FileInputStream( the path to the XLSX ));
workbook.save(bout, com.aspose.cells.SaveFormat.PDF);
System.out.println(workbook.getDefaultStyle().getFont());
}
The attached XLSX uses the font Algerian which is installed in the system fonts folder but not in the folder specified in the code above.
The attached PDF is what is produced by the above code: note that the PDF contains Algerian. That is, Aspose.Cells first falls back to the system fonts folder when it cannot find the font in the specified folder.
The output of the last line is
Aspose.Cells.Font [ Calibri; 11.0; Regular; com.aspose.cells.Color@0 ]
which is confusing, since the text in the XLSX is set in Algerian.
Hi Mario,
String fileName = “/home/babar/Downloads/a.xlsx”;
String out = “/home/babar/Downloads/output.pdf”;
//Set font directory; containing only Calibri and Algerian TTFs
CellsHelper.setFontDir(“/home/babar/Downloads/fonts”);
try {
FileOutputStream bout = new FileOutputStream(out);
Workbook workbook = new Workbook(fileName);
workbook.save(bout, SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
}
Hello,
I think you misunderstood my point. Let me explain the scenario I tested once again.
(1) The system font folder contains Algerian.
(2) The “Aspose” font folder does not contain Algerian but contains Calibri.
(3) The a.xlsx referes to Algerian.
(4) The code specifies that Aspose shall search for fonts in the “Aspose” font folder, which does not contain Algerian (see (2)).
(5) The conversion produces a.pdf which embeds Algerian even if Algerian is not in the font folder specified to Aspose.Cells.
This means that Aspose.Cells first checks if the required font is in the “Aspose” font folder specified with the invocation of CellsHelper.setFontDir().
If it does not find the font there, it then checks if it is in the system font folder. This is wrong: Aspose should only check the folder or list of folders explicitly specified (overriding any default) or there must be a way to specify that it should never check the sysem font folder.
What I expect when a font folder is explicitly given is that if a font is not there (e.g., Algerian), then it is substituted (e.g., with Calibri) without searching in the system font folder.
Is there a way to exclude the system font folder from the search path for fonts?
Hi Mario,
OK, thanks for filing a feature request.
Excluding system default font directories from the search path is very important to obtain identical results on different platforms. The only thing one has to ensure is a properly populated Aspose font directory, totally independent from the system folder and to configure Aspose software to search only there. This is much more robust and stable than depending on the system font folder.
Hi Mario,
Hi,
then Aspose.Cells will only use this font directory.
Thanks for the update.
However, I hope for a future API change that allows the programmer, rather than the deployer, to configure the font folder(s).
By this I mean there should be a way in the Aspose.Cells classes to specifiy the exact folders in the code and not depend on external parameters like a JVM command line argument (-D… argument to the JVM)
Regards
MR
Hi Mario,
The issues you have found earlier (filed as CELLSJAVA-40823) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi Mario,
System.setProperty(“Aspose.Cells.FontDirExc”, “FontDirSet”);
Hello,
thanks very much for the update!
Hi Mario,