C# 为什么courier字体在iText PDF文档中不起作用?
使用以下代码使用iText 5在C#中创建PDF文档。文本不会以courier字体呈现。为什么不呢C# 为什么courier字体在iText PDF文档中不起作用?,c#,itext,C#,Itext,使用以下代码使用iText 5在C#中创建PDF文档。文本不会以courier字体呈现。为什么不呢 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.G
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);
doc.Open();
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;
doc.Add(para);
}
doc.Close();
}
在iText5中,在向段落元素添加文本之前,必须指定字体(或者将其传递给构造函数) 改变
var para = new iTextSharp.text.Paragraph(line);
para.Font = font;
进入
var para = new iTextSharp.text.Paragraph(line, font);