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; } 

我试过使用其他字体,但它对我没有帮助(((

我该如何解决这个问题?

当您使用setFont() ,您可以更改设置字体添加的所有内容的Phrase字体。 您更改之前 ,内容"Номер"已出现在Phrase 。 因此, "Номер"以默认字体Helvetica表示。 由于Helvetica不知道如何表示西里尔字形,因此文本未呈现。