英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论