Sebastian Busek
Sebastian Busek

Reputation: 1032

How to setup special characters in iTextSharp on document

I want to create PDF from ASP.NET MVC. I found this library (http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3), which helps me. But when I want print special characters like „ř“, iTextShart doesn’t print it. I found, that I have to use

new Chunk("+ěščřžýáíé=", font); 

but I don’t know how to setup on BaseFont for all document not just for one paragraph. Can you help me please?

Upvotes: 0

Views: 2974

Answers (2)

Bereg Isztria
Bereg Isztria

Reputation: 21

You could prepare a new BaseFont, using the Fonts folder of the system:

string arialPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\arial.ttf";
BaseFont arial = BaseFont.CreateFont(arialPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font myFont = new Font(arial, 12, Font.NORMAL);
new Chunk("+ěščřžýáíé=", myFont);

Upvotes: 0

Huske
Huske

Reputation: 9296

I had a similar problem with Eastern European letters. Here is the piece of code that helped me solve the problem:

string fontPath = String.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "arial.ttf");
string title = "Some Title";

iTextSharp.text.Font fontTitle = iTextSharp.text.FontFactory.GetFont(fontPath, iTextSharp.text.pdf.BaseFont.CP1250, 22f);
iTextSharp.text.Paragraph paraTitle = new iTextSharp.text.Paragraph(title, fontTitle);
paraTitle.Alignment = iTextSharp.text.Element.ALIGN_CENTER;

document.Open();

document.Add(paraTitle);

What you are interested in is the fontTitle variable. This is how you create the base font for country page 1250. You will specify your own base font settings.

Upvotes: 1

Related Questions