当前位置: 首页 > 知识库问答 >
问题:

我怎么能通过iText7设置我的字体卡里布里?

凤修为
2023-03-14

我试图在我的Pdf文档上设置我的文本,但这不起作用。我怎么能通过iText7设置我的字体卡里布里?字体常量类只有有限的字体。

共有2个答案

商勇
2023-03-14

把这个放在这里,以防像我这样的人遇到这个问题,并且提供的解决方案不起作用。

我使用的方法的重载版本如下所示。

PdfFont calibri = PdfFontFactory.CreateFont(fontProgram, PdfEncodings.WINANSI, true);
萧焱
2023-03-14

如前所述,有一整章是关于字体的,有更多关于你能做什么、有什么不同等信息。

简而言之,您使用CreateFont加载字体文件

类似这样的东西将允许您设置每个段落元素的字体:

    FontProgram fontProgram =
        FontProgramFactory.CreateFont(@"C:\temp\calibri.ttf");
    PdfFont calibri = PdfFontFactory.CreateFont(fontProgram, PdfEncodings.WINANSI);
    using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(DEST)))
    {
        Document document = new Document(pdfDocument);
        document.Add(new Paragraph("Hello World!").SetFont(calibri));
    }

但您也可以对整个文档执行此操作:

    FontProgram fontProgram =
        FontProgramFactory.CreateFont(@"C:\temp\calibri.ttf");
    PdfFont calibri = PdfFontFactory.CreateFont(fontProgram, PdfEncodings.WINANSI);
    using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(DEST)))
    {
        Document document = new Document(pdfDocument);
        document.SetFont(calibri);
        document.Add(new Paragraph("Hello World!"));
    }
 类似资料:
  • 谢谢你的回应。我检查了位置,它被标识为与ANDROID_SDK_HOME环境路径相同的位置。它仍然说根是未定义的。我创建了一个到相同位置的ANDROID_SDK_ROOT环境路径,但它仍然没有定义。

  • 我试着用Java画一个长方形。我设置框架大小(800400)和可调整大小(假)矩形的x=50,y=50宽度=700高度=300。为什么不在中间呢?非常感谢。

  • 我得到了下面的结构: 我想把这个通过一个套接字发送到服务器,请求数据。我非常希望避免任何库,比如< code>protobuf。< code >杂货类型可以是1到255之间的任何值。一些食品杂货类型,比如类型< code>128,必须提供附加信息。仅仅提供类型< code>128是不够的,我还想提供字符串形式的< code>Cheeses。也就是说,与< code>128不同,type 必须提供一

  • 我使用Selenium编写了Java代码。当我运行代码时,它会抛出NullPointerException。检查下面的异常 我的代码如下:

  • 我有这段代码,但我不明白为什么会出现以下错误:

  • 在Android 4 . 4 . 2 < code > environment . getexternalstoratedirectory()上。getPath()返回< code>/storage/emulated/0但是这个路径在我的Nexus5 Android 4.4.2上不存在。< code > environment . getexternalstoratedirectory()。get