How to use System Font in iTextSharp with VB.net?

Can someone help me with writing the code to use a system font?

31st May 2016
admin-marketing

I'm using Itextsharp to convert text files to PDF documents dynamically using VB.net. However I need to use a system font that is not part of the iTextSharp library. I've seen some code examples using C#. However I'm a newbie in programming and my experience is all in Visual Basic. Can someone help me with writing the code to use a system font?

Posted on StackOverflow on May 2, 2015 by Don Wilson

I'll give you iText 7 code in Java, but it can be easily converted to C# as the terminology is identical.

Suppose that you want to use Arial regular and you have the file arial.ttf in your C:\windows\fonts directory, then creating the Font object is as easy as this:

PdfFont font = PdfFontFactory.createFont("c:/windows/fonts/arial.ttf", PdfEncodings.IDENTITY_H, true);

Using the font is easy too:

PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Paragraph p = new Paragraph("Hello World in Arial").setFont(font);
Document doc = new Document(pdfDoc).add(p);
doc.close();

This is almost a literal translation of the Java and C# examples that can be found in abundance. If this doesn't solve your problem, please show what you've tried and explain why it doesn't work.

Here's the code I'm going to attempt to use:

 

Dim fontpath As String = "C:\Windows\Fonts\"

Share this article

Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now