有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java iText PdfPTable不显示西里尔(俄语)符号

我为我的英语感到抱歉。 我正在尝试使用PdfPTable(iText库)创建表。 表格显示空栏![在此处输入图像描述][1]

public class CreatePDF {
File file;
BaseFont bf;
Font f_title;
Font f_text;

public void setFont() throws DocumentException, IOException{
    try{
        bf = BaseFont.createFont("/fonts/Times_New_Roman.ttf", BaseFont.IDENTITY_H , BaseFont.EMBEDDED); 
        f_title = new Font(bf, 14 );
        f_text = new Font(bf);
    }catch(Exception ex){
        ex.printStackTrace();
    }
}

public void make_invoice() throws DocumentException, IOException{
    setFont();
    Document doc = new Document(PageSize.A4);
    Desktop d = Desktop.getDesktop();
    try{
        file = new File("invoice.pdf");
        PdfWriter.getInstance(doc, new FileOutputStream(file));
        doc.open();
        Paragraph title = new Paragraph();
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(f_title);
        title.add("Счет фактура");//this work!

        doc.add(create_table());

        doc.close();

    }catch(Exception ex){
        ex.printStackTrace();
    }
}

public PdfPTable create_table() throws DocumentException{
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);
    table.setSpacingBefore(5f);

    PdfPCell cell;

    Phrase ph = new Phrase("Номер");//it's doesn't work ((
    ph.setFont(f_text);

    cell = new PdfPCell(ph);
    table.addCell(cell);
    table.addCell("Nuber");

    return table;
}

我试过用其他字体,但没用(((

我如何解决这个问题


共 (0) 个答案