Stephen Richter Stephen Richter - 9 months ago 45
C# Question

why courier font not working in iText PDF document?

Using the following code to create a PDF document in C# using iText 5. The text does not render in the courier font. Why not?

private void SimpleFontDoc(string pdfDocPath)
Document doc = new Document(PageSize.LETTER, 10, 10, 42, 30);
var fs = new FileStream(pdfDocPath, FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(doc, fs);

string[] lines = new string[]
"First text line",
"Second text line"
var font = FontFactory.GetFont("courier", 12.0f, BaseColor.BLACK);

foreach (var line in lines)
var para = new iTextSharp.text.Paragraph(line);
para.Font = font;



In iText5 you have to specify the font before adding text to the Paragraph element (or alternatively pass it to the constructor).


var para = new iTextSharp.text.Paragraph(line);
para.Font = font;


var para = new iTextSharp.text.Paragraph(line, font);