aspose-cells / Aspose.Cells-for-Java

Aspose.Cells for Java examples, plugins and showcases
https://products.aspose.com/cells/java
MIT License
146 stars 100 forks source link

AsposeCells for Java seems to ignore fonts #52

Closed j75 closed 3 years ago

j75 commented 3 years ago

Hi!

I am trying to convert an Excel file (test.xlsx from the attached zip) to PDF. test.zip

The Excel contains only a cell, written with the Angelina font downloaded from https://www.1001freefonts.com/angelina.font. When saving the workbook, I use PdfSaveOptions#setCompliance(PdfCompliance.PDF_A_1_B) and I am on a Linux computer (Ubuntu 20.04).

  1. if I don't install the font on my system, I have the result from the no_font.pdf file. Investigating the fonts from the PDF produces
    $ pdffonts no_font.pdf
    name                                 type              encoding         emb sub uni object ID
    ------------------------------------ ----------------- ---------------- --- --- --- ---------
    FAAABA+Tibetan_Machine_Uni           CID TrueType      Identity-H       yes yes yes     10  0
  2. now I install the font on my computer, I convert again the Excel and I get the with-angelina_font.pdf file. It has the same size, however the MD5 (for instance) is different (so the file is different) but pdffonts produces the same result!
  3. Now I am trying to see what's my default system font:
    $ fc-match 
    DejaVuSans.ttf: "DejaVu Sans" "Book"

So:

amjad-sahi commented 3 years ago

Please see the document for your reference. You need to first install the font and then set the fonts folder (the folder should be accessible seamlessly there should not be any rights issue) at the start of the program (before using any other Aspose.Cells APIs). This task is compulsory for non windows os (e.g. Linux). e.g. Sample code:

// Second parameter directs the API to search the sub folders for font files
FontConfigs.setFontFolder(your_font_folder, true);

Also the above document will explain the font substitution mechanism.

Regarding the process which Aspose.Cells API follows for selection of fonts, see the below details: 1) The API tries to find the fonts on the file system matching the exact font name used in the spreadsheet. 2) If API cannot find the fonts with the exact same name, it attempts to use the default font specified under the Workbook’s DefaultStyle.Font property. 3) If API cannot locate the font defined under the workbook’s DefaultStyle.Font property, it attempts to select the most suitable fonts from all of the available fonts. 4) Finally, if API cannot find any fonts on the file system, it renders the spreadsheet using Arial.

Moreover, see the document on how to specify individual or private set of fonts for workbook rendering for your reference.

j75 commented 3 years ago

At the 2nd paragraph I said that I installed the font in a standard Linux folder ("standard" for fontconfig) but I forget to add that I also performed fc-cache to update the font cache before running the program. And yes, then the font was used by the system (either by using fc-list or, as I said, by opening the Excel file with LibreOffice).

amjad-sahi commented 3 years ago

@j75 ,

It looks you have sorted out your issue. Let us know with details if you still find the issue.

j75 commented 3 years ago

Yes, your example from the documentation works, thank you.

amjad-sahi commented 3 years ago

Good to know that your issue sorted out by referring to the docs. Have a good day!