Styling issue with numbers and text in converted pdf, difference in local and higher environments

Hi @alexey.noskov ,

Hope you are doing great!!

I have styling issues with licensed aspose words for java product.

The issue that I am facing is , in my local machine the styling is working properly in converted pdf but in higher environment like QA the styling is breaking. I can see numbers in the pdf are like roman letters and text is also in different format. Do you saw these kind of cases before?

Here is the screenshots from local, this is what we want in our higher environemnet.

Below is screenshots from higher environment, we do not want below.

@alexey.noskov and team, please help us on this issue.

Thanks
Ramesh

@ramesh67 Most likely the problem occurs because the fonts used the documents are not available in the environment where documents are converted to PDF. To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/
Please try either installing or providing the fonts required to render the document. This should resolve the problem. If not, please attach your input and output documents along with problematic fonts here for testing, we will check the issue again and provide you more information.

Thanks for your response @alexey.noskov !!

I will follow the shared documents and will get back to you.

Hi @alexey.noskov ,

I am consuming fonts from 6 .ttf files. How I can feed aspose 6 .ttf files via java?

Thanks
Ramesh.

@ramesh67 You can simply put your 6 ttf files into a folder and use this folder as a font source as described above.

@alexey.noskov Those files are available in different server and I want to consume them as stream or bytes. Could you let me know how can I do this?

@ramesh67 In this case you can use StreamFontSource. Please see our documentation to learn how to load fonts from stream:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/#loading-fonts-from-stream

Hi @alexey.noskov

I have merged all my 6 ttf files into one and I have got stream from that file. After that I am using below code but I am still unable to see proper font and aspose words is always falling back to default font style(i.e. roman numbers format). Could you help further?

public myMethod(){
final com.aspose.words.Document doc = new com.aspose.words.Document();
FontSettings fontSettings = new FontSettings();
                fontSettings.setFontsSources(new FontSourceBase[]{new StreamFontSourceFile()});
                final DocumentBuilder builder = new DocumentBuilder(doc);
                builder.getDocument().setFontSettings(fontSettings);
                builder.getFont().setName("CustomName");

}

I have created a class for getting input stream as below

 private  class StreamFontSourceFile extends StreamFontSource  {
        public ByteArrayInputStream openFontDataStream() throws Exception{
		
		//this method will return ByteArrayInputStream;
		}
}

In the CSS we have defined our font-family as my custom font.

@ramesh67 Could you please clarify what you men by saying “I have merged all my 6 ttf files into one”? StreamFontSource is supposed to return one font.

@alexey.noskov
I have a custom font family which has 6 sub fonts like italic , regular bold etc. So I want to group all these fonts into one font and then send the same to StreamFontSource.

@ramesh67 You should load each of TTF fonts as a separate StreamFontSource. There is no way to load multiple TTF fonts using a single StreamFontSource.