How to change font size in PdfPTable?

I am using itextsharp to dynamically write to pdf. I am creating a table in a pdf document that contains the values ​​from the database. Can someone tell me how to change the font size of the values ​​in the table.

+5
source share
4 answers

Try the following:

Font fontH1 = new Font(Currier, 16, Font.NORMAL);

PdfPTable table = new PdfPTable(1);

table.AddCell(new PdfPCell(new Phrase(yourDatabaseValue,fontH1)));
+14
source

@Pabloker I'm not sure, but I get an error while using your solution. I cannot decide which font to use ( com.itextpdf.text.Font or com.lowagie.text.Font or java.awt.Font or org.apache.poi.ss.usermodel.Font ). Whatever I use, when I try to put it in a cell, it gives an error that such a constructor does not exist. Sorry, but I'm new to iText.

, , .

BaseFont bf = BaseFont.createFont(
                        BaseFont.TIMES_ROMAN,
                        BaseFont.CP1252,
                        BaseFont.EMBEDDED);
                Font font = new Font(bf, 12);
                PdfPCell pdfCell = new PdfPCell(new Phrase(sCellVal,font));

, com.itextpdf.text.Font, basefont com.itextpdf.text.pdf.BaseFont .

+1

Should I change the font size using the Font object that was passed when the text was created?

If you have not read it yet, this iText book is exceptional and will answer any question you may have: http://itextpdf.com/book/index.php

0
source

Try setting the font to PdfPTable.DefaultCell property

Example:

pdfTable.DefaultCell.Phrase = new Phrase() { Font = fontNormal };

I already answered this before: Set the font for all text from Pdfptable using Itextsharp

0
source

All Articles