iTextSharp Font interfering with common font

旧街凉风 提交于 2019-12-18 09:38:48

问题


I have included iTextSharp in my project to have an ability to create a PDF file. This is my code for this:

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();

And now the error comes up saying: Font is an ambiguous reference between System.Drawing.Font and iTextSharp.text.Font.

This is the code which is red underlined:

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);

回答1:


I assume you have these using directives:

using System.Drawing;
using iTextSharp.text;

Font is in both namespaces, so it's indeed ambiguous.

You can fully qualify it, to resolve ambiguity:

using System.Drawing;
using iTextSharp.text;

// ...

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

Or you can specify an alias:

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

// ...

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


来源:https://stackoverflow.com/questions/33574106/itextsharp-font-interfering-with-common-font

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!