Aspose HTML (Java): No Emojis in produced PDF

Aspose HTML (for Java) fails to render Emojis when converting this HTML (p:/tmp/originalFile.html):

<html>
 <body>
  Emojis: πŸ™‚πŸ€™πŸ€πŸ––πŸ‘‚πŸ‘…πŸ‘πŸ‰πŸ₯˜
 </body>
</html>

to PDF.

For example - Chrome browser renders the above HTML like:
Opened with Chrome.PNG (3.6 KB)

… while Aspose HTML shows only

Emojis:

string (without Emoji characters) after conversion to PDF.

The conversion was done using the following code:

import com.aspose.html.Configuration;
import com.aspose.html.Sandbox;
import com.aspose.html.drawing.Margin;
import com.aspose.html.drawing.Size;
import com.aspose.words.PaperSize;

import java.io.File;

class EmojiHtmlToPdf {

	public static void main(String[] args) {
		File inputFile = new File("p:/tmp/originalFile.html");
		File outputFile = new File("p:/tmp/convertedFile.pdf");


		com.aspose.html.HTMLDocument doc = new com.aspose.html.HTMLDocument(inputFile.getAbsolutePath());
		com.aspose.html.converters.Converter.convertHTML(doc, new com.aspose.html.saving.PdfSaveOptions(), outputFile.getAbsolutePath());
	}
	
}

Could you please give me some instruction of what would be a proper way for Emojis to show up in produced PDF?

I’ve also tried using the following Twitter (Mozilla) Emoji font:

With that in mind I’ve changed the HTML accordingly:

<html>
 <body style="font-family: Arial, sans-serif, 'Tweemoji Mozilla'">
  Emojis: πŸ™‚πŸ€™πŸ€πŸ––πŸ‘‚πŸ‘…πŸ‘πŸ‰πŸ₯˜
 </body>
</html>

, placed TwemojiMozilla.ttf inside β€œp:/tmp/” folder and then run the conversion like:

File inputFile = new File("p:/tmp/originalFile.html");
File outputFile = new File("p:/tmp/convertedFile.pdf");

// Set TwemojiMozilla.ttf font (which is placed inside tmp folder):
new FontsSettings().setFontsLookupFolders(new String[]{ "p:/tmp/"}, true);

// Convert HTML to PDF
com.aspose.html.HTMLDocument doc = new com.aspose.html.HTMLDocument(inputFile.getAbsolutePath());

com.aspose.html.converters.Converter.convertHTML(doc, new com.aspose.html.saving.PdfSaveOptions(), outputFile.getAbsolutePath());

Unfortunately the results were even worse:
image.png (704 Bytes)

Any help with this is highly appreciated.

@PrimosK

We have logged an issue as HTMLJAVA-831 in our issue tracking system to further investigate this scenario. We will look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

So at the moment there is no way to show Emojis?

@PrimosK

We need to investigate the PDF Export functionality of the API in order to further check whether it is possible or not. Which is why we logged the investigation ticket. As soon as the ticket is investigated, we will be able to share some feedback with you. Please give us some time.

We are sorry for the inconvenience.

hi,

Is there any solution? We met same problem, no emoji render after we convert html to pdf.
here is my code:

 HtmlLoadOptions options = new HtmlLoadOptions();
 Document document = new Document("C:\\Users\\xx\\Desktop\\1.html", options);
 document.save("C:\\Users\\xx\\Desktop\\1.pdf");

@lucy.hq

An issue as PDFJAVA-40745 has been logged in our issue management system after testing the scenario in our environment. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi,

@asad.ali, has any of HTMLJAVA-831 and PDFJAVA-40745 reported issues in this thread already been resolved?

@PrimosK

We would like to share with you that we have investigated the PDFJAVA-40745 completely. The basic answer is that the emojis are done using OpenType SVG fonts. Such fonts provide font definitions both in SVG format (basically SVG vector graphics) as well as in standard CFF or TrueType format for those applications that don’t support SVG format fonts.

At this point, the PDF specification, including the relatively new ISO 32000 PDF 2.0 specification does not support the SVG format in fonts.

We can suggest a workaround that will change emoji to some visible graphic symbol in UTF-8 in HTML. Then, after conversion to PDF, we could find this symbol and draw an SVG image above it. Please see the code snippet below.

    HtmlLoadOptions options = new HtmlLoadOptions();
    String HTML = FileUtils.readFileToString(new File("1.html"), "UTF-8");
    HTML = HTML.replace("πŸ˜…", "☻");
    FileUtils.writeStringToFile(new File("2.html"), HTML, "UTF-8");

    Document document = new Document("2.html", options);

    TextFragmentAbsorber absorber = new TextFragmentAbsorber("☻");
    document.getPages().accept(absorber);
    Page page = document.getPages().get_Item(1);
    for (TextFragment textFragment : absorber.getTextFragments()) {
        java.io.FileInputStream imageStream = new java.io.FileInputStream(new java.io.File("smile.png"));

        // Add an image to the Images collection of the page resources
        page.getResources().getImages().add(imageStream);

        // Using the GSave operator: this operator saves current graphics state
        page.getContents().add(new GSave());

        // Create Rectangle and Matrix objects
        Rectangle rectangle = new Rectangle(textFragment.getRectangle().getLLX(),
        textFragment.getRectangle().getLLY(),
        textFragment.getRectangle().getURX(),
        textFragment.getRectangle().getURY());
        Matrix matrix = new Matrix(new double[]{rectangle.getURX() - rectangle.getLLX(), 0, 0,
        rectangle.getURY() - rectangle.getLLY(), rectangle.getLLX(), rectangle.getLLY()});

        // Using ConcatenateMatrix (concatenate matrix) operator: defines how image must
        // be placed
        page.getContents().add(new ConcatenateMatrix(matrix));
        XImage ximage = page.getResources().getImages().get_Item(page.getResources().getImages().size());

        // Using Do operator: this operator draws image
        page.getContents().add(new Do(ximage.getName()));

        // Using GRestore operator: this operator restores graphics state
        page.getContents().add(new GRestore());
    }

    document.save("out.pdf"); 

1.zip (265 Bytes)
smile.jpg (74.1 KB)

About HTMLJAVA-831, the ticket is still pending for analysis. We will surely let you know as soon as we have definite updates regarding its resolution. Please spare us some time.

@asad.ali

As this workaround/hack is not generic I wonder whether any progress was made towards overall support for Emojis in Aspose (Java)?

@PrimosK

We are afraid that HTMLJAVA-831 is not yet resolved and no significant progress is made towards its resolution. We will surely inform you once we have additional updates about ticket resolution.

We apologize for your inconvenience.

@asad.ali

Was there any progress in this area?

Given the fact that emojis are present almost everywhere I would expect Aspose to handle these properly.

Could you please raise priority of this one?

@PrimosK

We are afraid that no significant progress has been made yet towards resolution of the ticket. It has been logged under free support model and there are other issues in the queue which were logged prior to it. We will surely look into this matter and let you know as soon as we have some definite updates regarding issue fix. We appreciate your patience and comprehension in this regard.

We apologize for the inconvenience.