I’m trying to find out a way to create pdf with emoji fonts support by using itextpdf 8.0.3.
I only found an example that came from itextpdf official website; https://kb.itextpdf.com/itext/pdfhtml-using-emojis-in-itext but it is talking about create pdf from html source.
I found an other example on Internet such as: https://kodejava.org/how-do-i-display-emoji-in-a-pdf-document-using-itext-8/.
There are some code as:
package org.kodejava.itext;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import java.io.IOException;
public class DocumentWithEmoji {
public static void main(String[] args) throws IOException {
PdfWriter writer = new PdfWriter("emoji.pdf");
PdfDocument pdf = new PdfDocument(writer);
try (Document document = new Document(pdf)) {
PdfFont fontEmoji = PdfFontFactory.createFont("seguiemj.ttf", PdfEncodings.IDENTITY_H);
Paragraph paragraph = new Paragraph()
.add(new Paragraph("Hello ").setFont(fontEmoji).setFontSize(20))
.add(new Paragraph("uD83DuDE00").setFont(fontEmoji).setFontSize(20)
.setFontColor(new DeviceRgb(243, 58, 106)));
document.add(paragraph);
} catch (Exception e) {
e.printStackTrace();
}
}
}
expected return should be:
but I got it as:
As you can see, it shows as red round dish instead of a red smile face.
Does anyone have such experience? if you do, please share some idea with me.