Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTextSharp Textfield setting the font to Bold

Tags:

c#

pdf

itext

For a textfield object, I would like to change the style to bold. I have already created the arial font since it is not a default font for the BaseFont object. Apparently the TextField object only takes the BaseFont as a valid font. I was wondering how would I change the style of the font that I have assigned to my textfield to bold. Is there a way to do this? here is my code that I have thus far

TextField txtNewField = new TextField(stamp.Writer, new Rectangle(1, 1, 75, 25), "TxtField"); 
BaseFont arial = BaseFont.CreateFont(@"c:\windows\fonts\arial.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED); 
txtNewField.FontSize = 8; 
txtNewField.Font = arial; 

Thank you in advance!

like image 626
Spidermain50 Avatar asked Mar 02 '26 15:03

Spidermain50


1 Answers

Have you tried specifying arialbd.ttf as the font name? I think that will give better results anyway, as the bold font will have been tuned.

(I'm not sure why you can't just specify a Font for a TextField, admittedly...)

like image 64
Jon Skeet Avatar answered Mar 04 '26 04:03

Jon Skeet