【问题标题】:iTextSharp Font interfering with common fontiTextSharp 字体干扰常见字体
【发布时间】:2015-11-06 19:19:11
【问题描述】:

我在我的项目中包含了 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);

【问题讨论】:

    标签: c# itextsharp


    【解决方案1】:

    我假设你有这些 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);
    

    【讨论】:

      猜你喜欢
      • 2015-08-04
      • 1970-01-01
      • 2014-05-21
      • 2016-12-11
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 2023-04-06
      • 2016-12-01
      相关资源
      最近更新 更多