2017-01-02 46 views
0

我正在使用iText PDF在Android中创建PDF文件。我需要在PDF中写入'$'符号。 我有以下代码: -iText PDF字体不会发生变化。卢比符号未显示

public static final String FONT1 = "/main/assets//PlayfairDisplay-Regular.ttf"; 
public static final String FONT2 = "/main/assets/PT_Sans-Web-Regular.ttf"; 
public static final String FONT3 = "/main/assets/FreeSans.ttf"; 
public static final String RUPEE = "The Rupee character \u20B9 and the Rupee symbol \u20A8"; 

这些被声明为类变量。 我有一个函数createPDF()写入PDF文档。 我的代码在功能上以下行: -

File pdfFile = new File(filePath); 
    OutputStream output = new FileOutputStream(pdfFile); 
    Document document = new Document(PageSize.A4); 
    PdfWriter.getInstance(document, output); 
    document.open(); 
    Font f1 = FontFactory.getFont(FONT1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); 
    Font f2 = FontFactory.getFont(FONT2, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); 
    Font f3 = FontFactory.getFont(FONT3, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); 
    Font f4 = FontFactory.getFont(FONT3, BaseFont.WINANSI, BaseFont.EMBEDDED, 12); 
    document.add(new Paragraph(RUPEE, f1)); 
    document.add(new Paragraph(RUPEE, f2)); 
    document.add(new Paragraph(RUPEE, f3)); 
    document.add(new Paragraph(RUPEE, f4)); 
    document.close(); 

然而无论是字体被反映在PDF也不卢比符号。 我的PDF看起来如下: -

Resulting PDF

我按照使用下面的链接步骤: - iText Developers TutorialStackOverflow Question on where to place Assets folder

我所知道的另一个相似的问题上SO: - Rupee symbol is not showing in android 然而这也没有帮助我。

我在这里做错了什么吗?我的字体是否放置在错误的位置?

+0

路径到您的字体是错的。我怎么知道? PDF中显示的所有文本都在Helvetica中(这是默认字体)。 –

+0

尝试,删除所有/主要/只是像资产/ PlayfairDisplay-Regular.ttf等等......并在第一个字体中,你也有//删除那个,并试试 – Raghavendra

+0

@BrunoLowagie。谢谢你的帮助:) –

回答

2

尝试, 全部删除/主/只保留像这样的资产/ PlayfairDisplay-Regular.ttf ...并在第一字体你有//删除一个过并尝试

相关问题