Save in PDF does not display UTF-8 characters

Hi,

I have a spreadsheet that contains various UTF-8 characters. When I save it into PDF format, all those characters are not displayed properly. There are squares injected instead.

ByteArrayOutputStream output = new ByteArrayOutputStream();
workbook.save(output, new PdfSaveOptions());

I also tried
workbook.save(output, new XlsSaveOptions(SaveFormat.PDF));

I would appreciate any help.
Thanks,
Olga

Hi Olga,


Thank you for contacting Aspose support.

Please note, Aspose.Cells for Java API requires the appropriate fonts to be present in the environment to render the characters correctly on the resultant PDF. In order to troubleshoot this matter on your end, please check the font family that represents the problematic characters in the Excel view then make sure that those font(s) are present in your environment. You may also direct the Aspose.Cells for Java API to pick these fonts using the CellsHelper.setFontDir method at the start of your application.

In case you are unable to workaround this situation, please provide us the input spreadsheet along with your environment details for our review. We will guide you further after reviewing the above required information.

Hi,

I always set font directory and everything is working properly with English characters. Here are two test files that I am testing with. Entry file testWorkbook.xlsx and resulting file testWorkbook.pdf that I get when saving .xlsx one. Entry file contains English, Russian and Hindu characters

Here is the code I use:
Workbook testWorkbook = new Workbook(filePath + “testWorkbook.xlsx”);
testWorkbook.save(filePath + “testWorkbook.pdf”);

As you can see PDF version does not display characters correctly.

Olga

Hi Olga,


Thank you for providing the sample spreadsheet and the resultant PDF.

Upon reviewing the provided PDF and re-generating the PDF on our end, the issue still seems to be related to the fact that you are missing the required fonts in your environment. Please have a look at the attached snapshots showing the embedded fonts in your provided PDF & the one generated on our side. You will notice that basic difference is that your PDF is lacking the Arial Unicode font that is required to properly render the text in the spreadsheet.

Please be kind enough to follow the below mentioned steps in order to troubleshoot this scenario further.

  • Download the attached archive that contains the TTF files for Calibri & Arial font families.
  • Extract the archive on your machine. Preferably in the Download folder as it would have access rights to your user.
  • Use the following code snippet to re-generate the PDF.

Java

CellsHelper.setFontDir(“full path to the folder containing the extracted TTF files”);
Workbook wb = new Workbook(“testWorkbook.xlsx”);
wb.save(“output.pdf”);


It is best that you should first verify the path specified as the parameter to the CellsHelper.setFontDir actually exists because Aspose.Cells for Java API will not throw an exception if you pass an invalid path or the TTF files do not exist on the specified path. Moreover, please try the case as stated above with your existing revision of Aspose.Cells for Java API. Hopefully the problem isn't in the API it self. However, in case the problem persists, give the scenario another try with latest version of Aspose.Cells for Java 8.3.0.x and share the generated PDF file here for review.

Note: The fonts attached to this post have been taken from a Windows platform and have been provided to you for testing purposes only. In case you wish to use these fonts in an environment other than Windows and/or on production server then please review the licensing information published by the vendor.

Hi,

I tested my spreadsheet with the provided set of fonts and the issue with the Russian characters was solved. There is still and issue with Hindu characters that are shown as squares. May be some fonts are still missing to display those.

Olga

Hi Olga,


Your understanding is correct, you have to place the TTC/TTF files corresponding to the Hindi characters in your environment and set the font location using the CellsHelper.setFontDir method. As you are already using the aforesaid method in your application so placing the required fonts in the same directory will fix the issue.