iText字体设置为Phrase未反映

huangapple go评论90阅读模式
英文:

iText Font set to Phrase not being reflected

问题

我正在尝试将字体添加到短语中,我正在使用iText 5。字体没有反映在文本中,我正在尝试设置的文本中。

如果有人遇到相同问题,请告诉我。```

英文:

I am trying to add font to phrase, I am using iText 5. Font is not being reflected in text that is being display for which I am trying to set.

Let me know If anybody came across the same.

private static void addDataToCell(PdfPTable table, String cellData, int border, Font font) {

    final Phrase phrase = new Phrase(cellData);
    if (font != null) {
      phrase.setFont(font);
    }
    PdfPCell cell = new PdfPCell(phrase);

    cell.setBorder(border);
    cell.setUseAscender(true);
    cell.setUseDescender(true);

    cell.setPaddingLeft(3);
    cell.setPaddingBottom(3);
    cell.setPaddingTop(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.addCell(cell);
  }

答案1

得分: 1

答案在下面的链接中:
https://itextpdf.com/en/resources/faq/fonts/itext-5-legacy/why-cant-i-set-font-phrase

简而言之,在创建Phrase时需要设置字体,而不是之后使用.setFont来设置。

new Phrase(cellData, font);
英文:

Answer is in below link
https://itextpdf.com/en/resources/faq/fonts/itext-5-legacy/why-cant-i-set-font-phrase

In short, we need to set font while creating Phrase, not afterwards like with .setFont

new Phrase(cellData, font);

huangapple
  • 本文由 发表于 2020年5月29日 23:23:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/62089354.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定