Reputation: 255
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);
}
Upvotes: 0
Views: 230
Reputation: 255
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);
Upvotes: 1