使用itext在pdf上添加UNICODE表情符号

时间:2018-03-21 11:14:28

标签: java unicode itext itext7

我在使用itext pdf创建的pdf上添加unicode表情符号时遇到了一些问题。我试过这个和itextpdf核心5.5.13

public class MathSymbols { 
public static final String DEST = "EXAMPLE.pdf";
public static final String FONT = "/res/fonts/arialuni.ttf";
public static String TEXT ;

public static void main(String[] args) throws IOException, DocumentException {
    File file = new File(DEST);
    TEXT = "this "+Character.toChars(0x1F600)+" string \uD83D\uDE00 contains \ud83d\ude00 special \u2609 characters like this  \u2208, \u2229, \u2211, \u222b, \u2206";
    new MathSymbols().createPdf(DEST);

}

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
   BaseFont bf = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    Font f = new Font(bf,12);
    Paragraph p = new Paragraph(TEXT, f);
    document.add(p);
    document.close();
}}

我在使用此代码段

的itextpdf 7.x上遇到了同样的问题
public class Main {

public static final String DEST = "example.pdf";

public static void main(String args[]) throws IOException {
    File file = new File(DEST);
    new Main().createPdf(DEST);
}

public void createPdf(String dest) throws IOException {
    PdfWriter writer = new PdfWriter(dest);
    PdfDocument pdf = new PdfDocument(writer);
    Document document = new Document(pdf);
    PdfFont f = PdfFontFactory.createFont("/resources/arialuni.ttf", PdfEncodings.IDENTITY_H,true);
    Paragraph p = new Paragraph("H\u2082SO\u2074 1 \uD83D\uDE00 contains \ud83d\ude00 spe \u2702 cial \u2609 characters like this  \u2208, \u2229, \u2211, \u222b, \u2206").setFont(f).setFontSize(10);
    document.add(p);
    document.close();
}}

我尝试使用不同的字体和不同的方式在像here这样的java中。 但我只是在pdf中找到了一个空格或一个正方形而没有表情符号

0 个答案:

没有答案