Missing text when convert word to pdf

I have submit an issue.
https://github.com/aspose-words/Aspose.Words-for-Java/issues/90

@liuyi520123 Unfortunately, I do not have baidu account. Could you please share the documents and fonts on google drive? Also, please note, this forum is the main place for getting support. So let’s continue discussion of the problem here.

I upload it again .Thank you.

https://timgsa.oss-cn-beijing.aliyuncs.com/word2pdf.zip @alexey.noskov

@liuyi520123 Thank you for additional information. As I case see in your code you specify only fz-fonts folder. the fonts in this folder does not have the required glyphs. If put both fz-fonts and sim-fonts into the fonts folder, the document is rendered fine:

Document doc = new Document("C:\\Temp\\in.docx");
doc.setFontSettings(new FontSettings());
doc.getFontSettings().setFontsFolder("C:\\Temp\\fonts", true);
doc.getFontSettings().getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("FZSongS-Extended");
doc.getLayoutOptions().setTextShaperFactory(HarfBuzzTextShaperFactory.getInstance());
doc.save("C:\\Temp\\out.pdf");

"C:\Temp\fonts" folder contains both fz-fonts and sim-fonts folder from your project. Here is output produced on my side: out.pdf (408.3 KB)

not include sim-fonts,only set fz-fonts. @alexey.noskov

@liuyi520123 Yes, the problem is reproducible if only fz-fonts are used. But this is not a bug. The problem occurs because these fonts does not have required glyphs. In this case Aspose.Words performs font fallback mechanism, i.e. Aspose.Words managed to find the requested font, but the fonts does not contain the required glyph.

It have all glyphs, you can delete FZSongS(SIP).TTF, it will show part of text, you delete FZSongS.TTF,it will show another part of text. And when i set font-family in word, it can show all text @alexey.noskov

@liuyi520123 MS Word behaves the same. If FZSong font is used in the document, MS Word also includes SimSun font because of missed glyphs.

Thank you, I will try MS WORD again, I used fontcreator open 2 fonts, I am sure it have all glyphs.
One program only use FZSongS(SIP), the out pdf out:
out-FZSongS(SIP).pdf (97.4 KB)
image.png (6.1 KB)

and other program use FZSongS, the pdf out:
outFZSongS.pdf (478.7 KB)
image.png (4.3 KB)

How can I let both fonts use in program. @alexey.noskov

@liuyi520123 You can configure fallback font setting. For example the following code gives me the correct result:

Document doc = new Document("C:\\Temp\\in.docx");
doc.setWarningCallback(new FontSubstitutionWarningCollector());
doc.setFontSettings(new FontSettings());
doc.getFontSettings().setFontsFolder("C:\\Temp\\fonts\\fz-fonts", true);
doc.getFontSettings().getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("FZSongS-Extended");
// Load modifed fallback settings.
doc.getFontSettings().getFallbackSettings().load("C:\\Temp\\test.xml");
doc.getLayoutOptions().setTextShaperFactory(HarfBuzzTextShaperFactory.getInstance());
doc.save("C:\\Temp\\out.pdf");

Here are modified fallback setting test.zip (1.1 KB)
Ans here is PDF document produced by this code: out.pdf (522.4 KB)

Fallback setting xml is the modified version of standard fallback setting, which you can get using code like this:

doc.getFontSettings().getFallbackSettings().save("C:\\Temp\\test.xml");

I have added FZSongS-Extended everywhere where SimSun font is specified to instruct Aspose.Words to use this font as a fallback.

@alexey.noskov Thank you very much.I once wanted to specify the corresponding font directly by searching word by RegEx, but I couldn’t find api to do this.

@liuyi520123 Please feel free to ask in case of any other issues, we will be glad to help you.

@alexey.noskov hi, I write text into .docx by program, and all text font-family is FZSongS-Extended, but some text depends on FZSongS-Extended(SIP),and it will missing some text wehn convert to PDF, May I converter to PDF by code-points even the fonts exist.

@liuyi520123 No, there is no such ability. Aspose.Words looks for glyphs in the font specified in the document, if glyph is missed font fallback mechanism goes in action. Aspose.Words allows you to adjust both font substitution and font fallback settings to make document rendering work with fonts available in your environment.
So in your case you should configure font fallback settings as I suggested earlier to make the document rendering work properly with both FZSongS fonts.