4
votes

I am using iTextSharp to create a new pdf-file. The pdf will contain one headline and one pdf-table. The file-size of the resultant pdf-file should be as small as possible, so I use the default font (Helvetica, 12pt). Is there a way to change the default-font-size from 12pt to 8pt.

I know that I can set the font for each pdf-table-cell.

But is it possible to set the default-font-size for the whole document/table, so that I don't need to set the font for each and every table-cell extra?

(I googled on this topic, but did not find an answer)

1
try this link --------------> stackoverflow.com/a/11577770/5323912 - N1gthm4r3
Setting a default font size for all objects is only possible in iText 7. If you are using an old version, you have to set a Font with the desired size for every separate object. Is there a reason why you chose to use an old version of iText? - Bruno Lowagie
Changing the font size will not make the file-size go down. - Joris Schellekens

1 Answers

7
votes

Try this

BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);


Paragraph p1 = new Paragraph(new Chunk("Sample text", font));