2015-11-06 72 views
0

我在项目中添加了iTextSharp,可以创建PDF文件。 这是我此代码:iTextSharp字体干扰普通字体

Document document = new Document(iTextSharp.text.PageSize.LETTER,20,20,42,35);    
PdfWriter writer = 
PdfWriter.GetInstance(document,newFileStream("Test.pdf",FileMode.Create)); 
document.Open(); 

Paragraph paragraph = new Paragraph("Test"); 

document.Add(paragraph); 

document.Close(); 

而且现在的错误出现说:字体是System.Drawing.Font和iTextSharp.text.Font之间不明确的引用。

这是红色下划线的代码:我假设你有这些using指令

RichTextBox tempBox = new RichTextBox(); 
tempBox.Size = new Size(650,60); 
tempBox.Font = new Font(FontFamily.GenericSansSerif,11.0F); //here is error 
flowLayoutPanel1.Controls.Add(tempBox); 

回答

3

using System.Drawing; 
using iTextSharp.text; 

Font是两个命名空间,所以它确实是不明确的。

您可以完全限定它,化解歧义:

using System.Drawing; 
using iTextSharp.text; 

// ... 

tempBox.Font = new System.Drawing.Font(FontFamily.GenericSansSerif,11.0F); 

或者你可以指定一个别名

using System.Drawing; 
using Font = System.Drawing.Font; 
using iTextSharp.text; 

// ... 

tempBox.Font = new Font(FontFamily.GenericSansSerif,11.0F);