When I save a word document containing Emojis to PDF using Aspose, the resulting PDF document lacks an Emoji.
Here is the sample code:
Document doc = new Document(inputFile);
FontSettings fontSettings = new FontSettings();
fontSettings.getSubstitutionSettings().getFontInfoSubstitution().setEnabled(true);
doc.setFontSettings(fontSettings);
HandleFontSubstitution callback = new HandleFontSubstitution();
doc.setWarningCallback(callback);
PdfSaveOptions options = new PdfSaveOptions();
doc.save("output.pdf", options);
System.out.println("PDF document created successfully.");
I will also upload the input document and an image showing the issue.
@blemmen
When converting a Word document containing emojis to PDF using Aspose, if one of the emojis is missing in the resulting PDF, it may be due to font substitution issues. Here are some steps you can take to troubleshoot and potentially resolve the issue:
-
Ensure Font Availability: Make sure that the font used in the Word document that contains the emoji is available on the system where the conversion is taking place. Emojis are often rendered using specific fonts like “Segoe UI Emoji” or “Apple Color Emoji”. If these fonts are not available, Aspose may not be able to render the emoji correctly.
-
Font Substitution Settings: You are already using font substitution settings in your code. Ensure that the font you are substituting for the missing emoji font is capable of rendering emojis. For example, you might want to add a substitution for “Segoe UI Emoji” to a font that supports emojis.
-
Fallback Settings: Consider implementing font fallback settings. This allows Aspose to use alternative fonts if the primary font does not contain the required glyphs (like emojis). You can define fallback rules in an XML file and load them into your FontSettings
.
-
Check for Warnings: Since you have set a warning callback, check if there are any warnings related to font substitution when you run your code. This can provide insights into which fonts are being substituted and why.
Here’s an example of how you might set up font fallback settings:
FontSettings fontSettings = new FontSettings();
fontSettings.FallbackSettings.Load("path_to_your_fallback_settings.xml");
doc.setFontSettings(fontSettings);
- Use the Correct Save Options: Ensure that you are using the correct
PdfSaveOptions
when saving the document. Sometimes, specific options can affect how fonts are embedded in the PDF.
If you continue to experience issues, consider checking the Aspose documentation for more details on font handling and emoji support, or reach out to the community for further assistance.
If you have the input document and an image showing the issue, sharing those could also help in diagnosing the problem more effectively.
Sources:
[1]: Manipulate and Substitute TrueType Fonts
This is the input document:
EmojiTest.docx (15.5 KB)
This is the issue (see green rectangles):
The issue is gone if you add some characters or if you add newlines before the missing emoji 
@blemmen
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-27993
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
I noticed that this is independent of the emoji, this happens with any first emoji in the next line.
@blemmen Thank you for additional information. We will keep you updated and let you know once it is resolved.
Thanks! I will update this ticket in case I find more information.
1 Like
@blemmen We have completed analyzing the issue and it was closed as not a bug. Aspose.Words supports surrogate pairs only with help of advance typography enabled.
You should render the document using the HarfBuzz nuget.
Document doc = new Document(MyDir + "in.doc");
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
doc.Save(MyDir + "Out.pdf");
Please see our documentation for more information:
https://docs.aspose.com/words/net/enable-opentype-features/
thanks for the quick reply. What are the drawbacks of enabling this feature?
Also how do I use it with Java?
When I try the following
doc.getLayoutOptions().setTextShaperFactory(HarfBuzzTextShaperFactory.getInstance());
I get an error because HarfBuzzTextShaperFactory cannot be found. It does not seem to be part of Aspose.Words for java. I am using version 24.12.
@blemmen Advanced typography features are supported by Aspose.Words via Aspose.Words.Shaping.HarfBuzz. You should be install the above package
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>24.10</version>
<classifier>jdk17</classifier>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>24.10</version>
<classifier>shaping-harfbuzz-plugin</classifier>
</dependency>
and modify the code as shown below:
// Open a document
Document doc = new Document("in.docx");
// When text shaper factory is set, layout starts to use OpenType features.
// An Instance property returns static BasicTextShaperCache object wrapping HarfBuzzTextShaperFactory
doc.getLayoutOptions().setTextShaperFactory(com.aspose.words.shaping.harfbuzz.HarfBuzzTextShaperFactory.getInstance());
// Render the document to PDF format
doc.save("out.pdf");
See more about advanced typograph features in the documentation:
https://docs.aspose.com/words/java/enable-opentype-features/
There should not be any drawbacks of enabling this feature.
thanks, I did not get that I need to specify it as classifier. It works now!
Good to hear. Not even performance impacts?
@blemmen In our internal tests, we did not observe any significant performance impact with or without OpenType features enabled.
great. On Windows using this does not seem to be an issue. But on linux I get this error:
java.lang.UnsatisfiedLinkError: 'long com.aspose.words.shaping.harfbuzz.HB.hb_buffer_create(int)'
at com.aspose.words.shaping.harfbuzz.HB.hb_buffer_create(Native Method)
at com.aspose.words.shaping.harfbuzz.zzXDb.<init>(Unknown Source)
at com.aspose.words.shaping.harfbuzz.zzWUn.zzXDb(Unknown Source)
at com.aspose.words.shaping.harfbuzz.zzWUn.zzXDb(Unknown Source)
at com.aspose.words.shaping.harfbuzz.zzWUn.shapeText(Unknown Source)
Any idea how to solve this?
@blemmen For Windows platforms no additional efforts are required for installing HarfBuzz because Aspose.Words.Shaping.Harfbuzz already includes compiled HarfBuzz library.
For other systems, Aspose.Words.Shaping.Harfbuzz relies on already installed HarfBuzz library. For instance, many Linux-based systems have HarfBuzz installed system-wide by default. If not, there is usually a package available for installing via package manager.
For example in the clear Ubuntu Docker image it is required to additionally install Harfbuzz using command like this:
RUN apt-get update && apt-get install -y libharfbuzz-dev
I still get the same error after installing harfbuzz-devel. This is what got installed:
Installed:
glib2-devel-2.56.4-161.el8.x86_64 graphite2-devel-1.3.10-10.el8.x86_64
harfbuzz-devel-1.7.5-4.el8.x86_64 harfbuzz-icu-1.7.5-4.el8.x86_64
libicu-60.3-2.el8_1.x86_64 libicu-devel-60.3-2.el8_1.x86_64
pcre-cpp-8.42-6.el8.x86_64 pcre-devel-8.42-6.el8.x86_64
pcre-utf16-8.42-6.el8.x86_64 pcre-utf32-8.42-6.el8.x86_64
Complete!
@blemmen,
To use HarfBuzz Plugin on Linux systems, you need to install the following package, similar to Windows:
...
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>25.2</version>
<classifier>shaping-harfbuzz-plugin</classifier>
</dependency>
...
Additionally, please note that this plugin is compatible with GLIBC 2.35. If your version is lower, there is a special HarfBuzz Legacy Plugin, compatible with GLIBC 2.33. To download, use
...
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>25.2</version>
<classifier>shaping-harfbuzz-legacy-plugin</classifier>
</dependency>
...
the system has glibc 2.28 installed and I tried using the legacy plugin, but it also does not work - same error.
@blemmen
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSJAVA-3037
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The issues you have found earlier (filed as WORDSNET-27993,WORDSJAVA-3037) have been fixed in this Aspose.Words for Java 25.4 update.