Hello,
I am working on project to convert Microsoft Word document to pdf using Aspose.Words version 24.2, however encountering a problem when the input word document contains a Microsoft’s Symbol font symbol inserted in it.
Since Microsoft’s Symbol font is not present on the machine I am using, I have defined following rules to substitute the licensed Microsoft Symbol font to a free font which is similar to it. Below is the code I am using for substitution:
Document doc = new Document(sourceFilePath, wordLoadOptions);
private static FontSettings wordsFontSettings;
wordsFontSettings = new FontSettings();
wordsFontSettings.getSubstitutionSettings().getTableSubstitution()
.setSubstitutes(Symbol, UnicodeSymbol);
doc.setFontSettings(wordsFontSettings );
final PdfSaveOptions options = new PdfSaveOptions();
doc.save(outputFilePath, options);
Still I am not getting to see the expected symbol on the generated pdf document when the symbol is inserted using Insert->Symbol in word document.
Please find this zip for further info:
Symbol_Issue.zip (161.1 KB)
From attached zip file, you can see that:
I am getting expected output, when the symbol is added by selecting Symbol font from fonts and then adding it by Shift + W (from keyboard).
However when symbol added by Insert->Symbol way, the substitution dosen’t work. Instead of actual symbol, an empty box or rectangle is seen.
Why is it not working when symbol is inserted this way?
How to manage this case ?
@aakanksha76 As I can see symbols in your document are inserted differently. When symbol is insert using Insert Symbol
it is represented like this:
<w:sym w:font="Symbol" w:char="F057"/>
When it is inserted using Shift+W
, it is inserted like this:
<w:r>
<w:rPr>
<w:rFonts w:ascii="Symbol" w:hAnsi="Symbol"/>
</w:rPr>
<w:t>W</w:t>
</w:r>
Most likely the problem on your side occurs because of a known peculiarity - Windows “Symbol” font is a symbolic font (like “Webdings”, “Wingdings”, etc.) which uses Unicode PUA. MacOS or Linux “Symbol” font on the other hand is a proper Unicode font (for example Greek characters are in the U+0370…U+03FF Greek and Coptic block). So these fonts are incompatible and Mac/Linux “Symbol” font cannot be used instead of Windows “Symbol” without additional actions. So in your “Symbol” font the char code F057
is not mapped to the proper glyph, while W
is.
Hi,
Thank you for the explanation! I would like to ask if there is any Aspose.Words API that can detect whether the Windows Symbol font is used in the text and retrieve the Number Format(like, “\uF057”) of that symbol from the Word document.?
Because I have achieved same for list in word document for Wingdings font as below:
// -- Replace bullets by unicode characters
for (com.aspose.words.List lst : doc.getLists()) {
for (com.aspose.words.ListLevel level : lst.getListLevels()) {
if (level.getFont().getName().equals("Wingdings")) {
LOGGER.debug("Font name is "+ level.getFont().getName());
switch (level.getNumberFormat()) {
case "\uF0A7": // Square bullet
level.setNumberFormat("\u25AA");
break;
case "\uF071": // Hollow Square bullet
level.setNumberFormat("\u2751");
break;
case "\uF0D8": // Right Arrow bullet
level.setNumberFormat("\u27A2");
break;
case "\uF0FC": // Checkmark bullet
level.setNumberFormat("\u2713");
break;
}
}
}
This was done for the list in the word document. I want to do it for the text now, is there a way to get the similar Number Format for text as there is for list?
@aakanksha76 You can use find/replace functionality to replace symbols in your document.
Document doc = new Document("C:\\Temp\\in.docx");
doc.getRange().replace("\uF057", "W");
doc.save("C:\\Temp\\out.docx");
@alexey.noskov Thank you for the response
This worked!
1 Like
Hi,
doc.getRange().replace("\uF057", "\u2126");
this worked but one concern that I have is, there are many number of symbols in the Windows Symbol font and defining the above rule for these many symbols does not look a feasible solution so, is there any particular solution to this problem?
@aakanksha76 I am afraid, there is no general solution for this.
Okay…
Thanks for the response
1 Like