Display Gridview with Marathi Data in PDF File using asp.net c#

Mohit Joshi 1 Reputation point

I am creating 1 application in which I am populating Data in Marathi language in Gridview. I want to create PDF of this Gridview. I am using iTextSharp to create PDF but it is not showing Marathi Data on that File.
PFB code for PDF : -

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using iTextSharp.tool.xml;
using System.Globalization;
using System.IO;
public void VarReport()
//if (DateTime.Now.Day >= 1 && DateTime.Now.Day <= 5 && DateTime.Now.Month % 2 == 0)
string filename = "Var_" + dt.GetMonthName(DateTime.Now.Month) + "_" + DateTime.Now.Year+".pdf";
using (StringWriter sw = new StringWriter())
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
VadhuVarData.AllowPaging = false;
StringReader sr = new StringReader(sw.ToString());
Document doc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(doc);
PdfWriter pw = PdfWriter.GetInstance(doc, Response.OutputStream);
Paragraph para = new Paragraph();
para.Add("वर यादी");
XMLWorkerHelper.GetInstance().ParseXHtml(pw, doc, sr);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Gridview is as in below image
PDF is showing as in below image

I kindly request to provide me with exact working code for that.
Thank You

ASP.NET Web Forms
ASP.NET Web Forms
A part of the ASP.NET web application framework that can be used to create ASP.NET web applications.
408 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,999 questions
{count} votes

1 answer

Sort by: Most helpful
  1. QiYou-MSFT 851 Reputation points Microsoft Employee

    Hi @Mohit Joshi ,
    The reason for your problem is that itextsharp does not have a Marathi language. But we can add this language manually.
    I'm sorry I don't have Marathi in my system because of the region, but I can show you Chinese way.

    1. First we open the text library of our system.
      It is located at: C:\Windows\Fonts
    2. Create the specified font BaseFont baseFont = BaseFont.CreateFont(
      "C:\WINDOWS\FONTS\Your font file .ttf",
      iTextSharp.text.Font titleFont = new iTextSharp.text.Font(baseFont, 18);

    3.Introduced System.Text.Encoding.CodePages in Nuget:


    Best Regards
    Qi You

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.