gpt4 book ai didi

java - iText PDF 字体不会发生变化。卢比符号未显示

转载 作者:行者123 更新时间:2023-12-02 03:08:22 26 4
gpt4 key购买 nike

我正在使用 iText PDF 在 android 中创建 PDF 文件。我需要在 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();

但是,字体和卢比符号都没有反射(reflect)在 PDF 中。我的 PDF 如下所示:-

Resulting PDF

我已使用以下链接执行步骤:- iText Developers TutorialStackOverflow Question on where to place Assets folder

我知道另一个类似的问题:- Rupee symbol is not showing in android但这也没有帮助我。

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

最佳答案

尝试一下,删除所有/main/只需保留 asset/PlayfairDisplay-Regular.ttf 等...并且在第一个字体中,您也//删除该字体并尝试

关于java - iText PDF 字体不会发生变化。卢比符号未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41425384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com