, 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)
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 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.
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 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");
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.
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 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.