简体   繁体   中英

Error in applying font size to iTextsharp PDF windows forms using C#

I am very new to C# and I am creating a small program to create PDF invoices. All I need to do is set the font size of my text within a table cell, however the recommended methods are not working at all. I am working in Visual Studio 2019 and using iTextSharp version 5.5.13.1. Here is my attempt:

PdfPCell cell3 = new PdfPCell(new Phrase(float.Parse("Quantity"), new Font(Font.HELVETICA, 8f, Font.NORMAL, Color.YELLOW)));

But I got an error:

'Font' is an ambiguous reference between System.Drawing.Font and iTextSharp.text.Font`.

However I figured this one out in that I have to destinguish between which font source I am using (Not sure if I am saying this correctly.). So I tried the following:

PdfPCell cell3 = new PdfPCell(new Phrase(float.Parse("Quantity"), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8f, iTextSharp.text.Font.NORMAL)));

But now I am getting an error:

Argument 2: Cannot convert from iTextSharp.text.Font to iTextSharp.text.Chunk.

All I want is to set the font size...

You can use the below method.

using iTextSharp.text;
using iTextSharp.text.pdf;

PdfPCell cell3 = new PdfPCell(new Phrase("Phrase", new Font(iTextSharp.text.Font.FontFamily.COURIER, 16, iTextSharp.text.Font.NORMAL)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM