'Font' is an ambiguous reference between System.Drawing.Font and iTextSharp.text.Font [duplicate]
This question already has an answer here:
iTextSharp Font interfering with common font
1 answer
I am trying to export a formatted Pdf file using the code below.I tried to fully qualify the 'Font' but i still get the same error and even more. This error flagged after fully qualifying the 'Font' ,'Argument 1:cannot convert from 'iTextSharp.text.pdf.BaseFont' to 'System.Drawing.FontFamily'.This is the code.
void ExportDataTableToPdf(DataTable dtaTable, String strPdfPath, string strHeader)
{
System.IO.FileStream fs = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
Document document = new Document();
document.SetPageSize(iTextSharp.text.PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
//Report header
BaseFont bsHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsHead = new Font(bsHead, 16, 1, Color.Gray); /***Red underlined code ***/
Paragraph pfgHeading = new Paragraph();
pfgHeading.Alignment = Element.ALIGN_CENTER;
pfgHeading.Add(new Chunk(strHeader.ToUpper(), fsHead));
document.Add(pfgHeading);
//Author
Paragraph prgAuthor = new Paragraph();
BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsAuthor = new Font(btnAuthor, 8, 2, Color.Gray); /***Red underlined code ***/
prgAuthor.Alignment = Element.ALIGN_RIGHT;
prgAuthor.Add(new Chunk("Author:2Deep", fsAuthor));
prgAuthor.Add(new Chunk("nRun Date:" + DateTime.Now.ToShortDateString(), fsAuthor));
document.Add(prgAuthor);
//Line separator
Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, Color.Black, ,Element.ALIGN_LEFT)));
document.Add(p);
//line break
document.Add(new Chunk("n", fsHead));
//Write Table
PdfPTable table = new PdfPTable(dtaTable.Columns.Count);
//Table Header
BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fntColumnHeader = new Font(btnColumnHeader, 10, 1, Color.White); /***Red underlined code ***/
for (int i = 0; i < dtaTable.Columns.Count; i++)
{
PdfPCell cell = new PdfPCell(); /***Red underlined code ***/
cell.BackgroundColor = Color.Gray;
cell.AddElement(new Chunk(dtaTable.Columns[i].ColumnName.ToUpper(), fntColumnHeader));
table.AddCell(cell);
}
//table data
for (int i=0; i < dtaTable.Rows.Count; i++)
{
for (int j=0; j < dtaTable.Columns.Count; j++)
{
table.AddCell(dtaTable.Rows[i][j].ToString());
}
}
document.Add(table);
document.Close();
writer.Close();
fs.Close();
c# fonts itext
marked as duplicate by mjwills, John, Tetsuya Yamamoto, Selvin, user6655984 Nov 14 '18 at 3:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
iTextSharp Font interfering with common font
1 answer
I am trying to export a formatted Pdf file using the code below.I tried to fully qualify the 'Font' but i still get the same error and even more. This error flagged after fully qualifying the 'Font' ,'Argument 1:cannot convert from 'iTextSharp.text.pdf.BaseFont' to 'System.Drawing.FontFamily'.This is the code.
void ExportDataTableToPdf(DataTable dtaTable, String strPdfPath, string strHeader)
{
System.IO.FileStream fs = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
Document document = new Document();
document.SetPageSize(iTextSharp.text.PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
//Report header
BaseFont bsHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsHead = new Font(bsHead, 16, 1, Color.Gray); /***Red underlined code ***/
Paragraph pfgHeading = new Paragraph();
pfgHeading.Alignment = Element.ALIGN_CENTER;
pfgHeading.Add(new Chunk(strHeader.ToUpper(), fsHead));
document.Add(pfgHeading);
//Author
Paragraph prgAuthor = new Paragraph();
BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsAuthor = new Font(btnAuthor, 8, 2, Color.Gray); /***Red underlined code ***/
prgAuthor.Alignment = Element.ALIGN_RIGHT;
prgAuthor.Add(new Chunk("Author:2Deep", fsAuthor));
prgAuthor.Add(new Chunk("nRun Date:" + DateTime.Now.ToShortDateString(), fsAuthor));
document.Add(prgAuthor);
//Line separator
Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, Color.Black, ,Element.ALIGN_LEFT)));
document.Add(p);
//line break
document.Add(new Chunk("n", fsHead));
//Write Table
PdfPTable table = new PdfPTable(dtaTable.Columns.Count);
//Table Header
BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fntColumnHeader = new Font(btnColumnHeader, 10, 1, Color.White); /***Red underlined code ***/
for (int i = 0; i < dtaTable.Columns.Count; i++)
{
PdfPCell cell = new PdfPCell(); /***Red underlined code ***/
cell.BackgroundColor = Color.Gray;
cell.AddElement(new Chunk(dtaTable.Columns[i].ColumnName.ToUpper(), fntColumnHeader));
table.AddCell(cell);
}
//table data
for (int i=0; i < dtaTable.Rows.Count; i++)
{
for (int j=0; j < dtaTable.Columns.Count; j++)
{
table.AddCell(dtaTable.Rows[i][j].ToString());
}
}
document.Add(table);
document.Close();
writer.Close();
fs.Close();
c# fonts itext
marked as duplicate by mjwills, John, Tetsuya Yamamoto, Selvin, user6655984 Nov 14 '18 at 3:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
iTextSharp Font interfering with common font
1 answer
I am trying to export a formatted Pdf file using the code below.I tried to fully qualify the 'Font' but i still get the same error and even more. This error flagged after fully qualifying the 'Font' ,'Argument 1:cannot convert from 'iTextSharp.text.pdf.BaseFont' to 'System.Drawing.FontFamily'.This is the code.
void ExportDataTableToPdf(DataTable dtaTable, String strPdfPath, string strHeader)
{
System.IO.FileStream fs = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
Document document = new Document();
document.SetPageSize(iTextSharp.text.PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
//Report header
BaseFont bsHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsHead = new Font(bsHead, 16, 1, Color.Gray); /***Red underlined code ***/
Paragraph pfgHeading = new Paragraph();
pfgHeading.Alignment = Element.ALIGN_CENTER;
pfgHeading.Add(new Chunk(strHeader.ToUpper(), fsHead));
document.Add(pfgHeading);
//Author
Paragraph prgAuthor = new Paragraph();
BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsAuthor = new Font(btnAuthor, 8, 2, Color.Gray); /***Red underlined code ***/
prgAuthor.Alignment = Element.ALIGN_RIGHT;
prgAuthor.Add(new Chunk("Author:2Deep", fsAuthor));
prgAuthor.Add(new Chunk("nRun Date:" + DateTime.Now.ToShortDateString(), fsAuthor));
document.Add(prgAuthor);
//Line separator
Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, Color.Black, ,Element.ALIGN_LEFT)));
document.Add(p);
//line break
document.Add(new Chunk("n", fsHead));
//Write Table
PdfPTable table = new PdfPTable(dtaTable.Columns.Count);
//Table Header
BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fntColumnHeader = new Font(btnColumnHeader, 10, 1, Color.White); /***Red underlined code ***/
for (int i = 0; i < dtaTable.Columns.Count; i++)
{
PdfPCell cell = new PdfPCell(); /***Red underlined code ***/
cell.BackgroundColor = Color.Gray;
cell.AddElement(new Chunk(dtaTable.Columns[i].ColumnName.ToUpper(), fntColumnHeader));
table.AddCell(cell);
}
//table data
for (int i=0; i < dtaTable.Rows.Count; i++)
{
for (int j=0; j < dtaTable.Columns.Count; j++)
{
table.AddCell(dtaTable.Rows[i][j].ToString());
}
}
document.Add(table);
document.Close();
writer.Close();
fs.Close();
c# fonts itext
This question already has an answer here:
iTextSharp Font interfering with common font
1 answer
I am trying to export a formatted Pdf file using the code below.I tried to fully qualify the 'Font' but i still get the same error and even more. This error flagged after fully qualifying the 'Font' ,'Argument 1:cannot convert from 'iTextSharp.text.pdf.BaseFont' to 'System.Drawing.FontFamily'.This is the code.
void ExportDataTableToPdf(DataTable dtaTable, String strPdfPath, string strHeader)
{
System.IO.FileStream fs = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
Document document = new Document();
document.SetPageSize(iTextSharp.text.PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
//Report header
BaseFont bsHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsHead = new Font(bsHead, 16, 1, Color.Gray); /***Red underlined code ***/
Paragraph pfgHeading = new Paragraph();
pfgHeading.Alignment = Element.ALIGN_CENTER;
pfgHeading.Add(new Chunk(strHeader.ToUpper(), fsHead));
document.Add(pfgHeading);
//Author
Paragraph prgAuthor = new Paragraph();
BaseFont btnAuthor = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fsAuthor = new Font(btnAuthor, 8, 2, Color.Gray); /***Red underlined code ***/
prgAuthor.Alignment = Element.ALIGN_RIGHT;
prgAuthor.Add(new Chunk("Author:2Deep", fsAuthor));
prgAuthor.Add(new Chunk("nRun Date:" + DateTime.Now.ToShortDateString(), fsAuthor));
document.Add(prgAuthor);
//Line separator
Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, Color.Black, ,Element.ALIGN_LEFT)));
document.Add(p);
//line break
document.Add(new Chunk("n", fsHead));
//Write Table
PdfPTable table = new PdfPTable(dtaTable.Columns.Count);
//Table Header
BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font fntColumnHeader = new Font(btnColumnHeader, 10, 1, Color.White); /***Red underlined code ***/
for (int i = 0; i < dtaTable.Columns.Count; i++)
{
PdfPCell cell = new PdfPCell(); /***Red underlined code ***/
cell.BackgroundColor = Color.Gray;
cell.AddElement(new Chunk(dtaTable.Columns[i].ColumnName.ToUpper(), fntColumnHeader));
table.AddCell(cell);
}
//table data
for (int i=0; i < dtaTable.Rows.Count; i++)
{
for (int j=0; j < dtaTable.Columns.Count; j++)
{
table.AddCell(dtaTable.Rows[i][j].ToString());
}
}
document.Add(table);
document.Close();
writer.Close();
fs.Close();
This question already has an answer here:
iTextSharp Font interfering with common font
1 answer
c# fonts itext
c# fonts itext
edited Nov 14 '18 at 3:03
John
11.9k32038
11.9k32038
asked Nov 14 '18 at 2:58
user8840249user8840249
187
187
marked as duplicate by mjwills, John, Tetsuya Yamamoto, Selvin, user6655984 Nov 14 '18 at 3:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by mjwills, John, Tetsuya Yamamoto, Selvin, user6655984 Nov 14 '18 at 3:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You have using System.Drawing;
and using 'iTextSharp.text.pdf;
at the top of your code file (or within the namespace definition).
Now, in System.Drawing
there is a Font
type, and likewise in iTextSharp.text.pdf
there is also a Font
object. Visual Studio is unable to determine which one you want to use, so you have to stop the situation being ambiguous.
You can do this in a number of ways:
- Remove the unwanted using (if you're using nothing from
System.Drawing
, for example, remove theusing System.Drawing;
declaration). - Explicitly state the type you want to use in your code. Instead of
Font a = new Font()
, useSystem.Drawing.Font a = new System.Drawing.Font();
- Alias the type with a
using
statement:using TheFont = System.Drawing.Font
and then in your code write something likeTheFont = new TheFont();
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have using System.Drawing;
and using 'iTextSharp.text.pdf;
at the top of your code file (or within the namespace definition).
Now, in System.Drawing
there is a Font
type, and likewise in iTextSharp.text.pdf
there is also a Font
object. Visual Studio is unable to determine which one you want to use, so you have to stop the situation being ambiguous.
You can do this in a number of ways:
- Remove the unwanted using (if you're using nothing from
System.Drawing
, for example, remove theusing System.Drawing;
declaration). - Explicitly state the type you want to use in your code. Instead of
Font a = new Font()
, useSystem.Drawing.Font a = new System.Drawing.Font();
- Alias the type with a
using
statement:using TheFont = System.Drawing.Font
and then in your code write something likeTheFont = new TheFont();
add a comment |
You have using System.Drawing;
and using 'iTextSharp.text.pdf;
at the top of your code file (or within the namespace definition).
Now, in System.Drawing
there is a Font
type, and likewise in iTextSharp.text.pdf
there is also a Font
object. Visual Studio is unable to determine which one you want to use, so you have to stop the situation being ambiguous.
You can do this in a number of ways:
- Remove the unwanted using (if you're using nothing from
System.Drawing
, for example, remove theusing System.Drawing;
declaration). - Explicitly state the type you want to use in your code. Instead of
Font a = new Font()
, useSystem.Drawing.Font a = new System.Drawing.Font();
- Alias the type with a
using
statement:using TheFont = System.Drawing.Font
and then in your code write something likeTheFont = new TheFont();
add a comment |
You have using System.Drawing;
and using 'iTextSharp.text.pdf;
at the top of your code file (or within the namespace definition).
Now, in System.Drawing
there is a Font
type, and likewise in iTextSharp.text.pdf
there is also a Font
object. Visual Studio is unable to determine which one you want to use, so you have to stop the situation being ambiguous.
You can do this in a number of ways:
- Remove the unwanted using (if you're using nothing from
System.Drawing
, for example, remove theusing System.Drawing;
declaration). - Explicitly state the type you want to use in your code. Instead of
Font a = new Font()
, useSystem.Drawing.Font a = new System.Drawing.Font();
- Alias the type with a
using
statement:using TheFont = System.Drawing.Font
and then in your code write something likeTheFont = new TheFont();
You have using System.Drawing;
and using 'iTextSharp.text.pdf;
at the top of your code file (or within the namespace definition).
Now, in System.Drawing
there is a Font
type, and likewise in iTextSharp.text.pdf
there is also a Font
object. Visual Studio is unable to determine which one you want to use, so you have to stop the situation being ambiguous.
You can do this in a number of ways:
- Remove the unwanted using (if you're using nothing from
System.Drawing
, for example, remove theusing System.Drawing;
declaration). - Explicitly state the type you want to use in your code. Instead of
Font a = new Font()
, useSystem.Drawing.Font a = new System.Drawing.Font();
- Alias the type with a
using
statement:using TheFont = System.Drawing.Font
and then in your code write something likeTheFont = new TheFont();
answered Nov 14 '18 at 3:03
JohnJohn
11.9k32038
11.9k32038
add a comment |
add a comment |