无法使用iText将越南字符导出为PDF

无法使用iText将越南字符导出为PDF

问题描述:

我正在尝试使用iText将越南字符导出为PDF。我试图使用

I'm trying to export Vietnamese characters to PDF using iText. I tried to use

BaseFont bf = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

它正确显示一些unicode字符,例如俄语,但不是带有越南语口音的字符( ạ,ã,ố等)。
这是我写的课程:

It displays some unicode characters correctly, for example Russian, but not the ones with accents in Vietnamese language (ạ,ã,ố etc.). Here's the class I wrote:

public class PDFMaker {
private final static String FILE = "FilePdf.pdf";
public static File fontFile = new File("fonts/arialuni.ttf");
public static void makePDF() throws IOException{
    try{    
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(FILE));
        BaseFont bf = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font font = new Font(bf,15);
        document.open();
        document.add(new Paragraph("Đại học bách khoa Hà Nội", font)); 
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        e.printStackTrace(System.out);
    }}

显示:ĐibcáchkhoaHàNi。请帮忙。

It displays: Đi hc bách khoa Hà Ni. Please help.

字符未显示,因为MS Arial Unicode不知道这些字符。你需要使用另一种字体。例如:我下载了一个包名的Vietnames来自SourceForge的字体和我用你的代码示例中的arialuni.ttf替换了vuArial.ttf(在下载的软件包中找到)。使用该字体时,所有字符都可见。

The characters aren't shown, because MS Arial Unicode doesn't know those characters. You need to use another font. For instance: I downloaded a package of Vietnames fonts from SourceForge and I replaced arialuni.ttf in your code sample with vuArial.ttf (found in the downloaded package). When using that font, all the characters were visible.