iTextSharp 字体干扰普通字体
iTextSharp Font interfering with common font
我在我的项目中包含了 iTextSharp,以便能够创建 PDF 文件。
这是我的代码:
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();
现在出现错误:Font is an ambiguous reference between System.Drawing.Font and iTextSharp.text.Font.
这是带红色下划线的代码:
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);
我假设您有这些 using
指令:
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);
我在我的项目中包含了 iTextSharp,以便能够创建 PDF 文件。 这是我的代码:
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();
现在出现错误:Font is an ambiguous reference between System.Drawing.Font and iTextSharp.text.Font.
这是带红色下划线的代码:
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);
我假设您有这些 using
指令:
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);