如何使用asp.net在印地文中创建pdf

时间:2017-11-08 11:09:20

标签: c# asp.net pdf itext hindi

我正在使用asp.net创建pdf 我成功地用英语创建了pdf 但是当我用印地文语言获取数据时,它在pdf中显示为空白。 我怎样才能在印地文中获取数据? 这是我的代码

protected void GenerateReport(object sender, EventArgs e)
{
    DataRow dr = GetData("SELECT * FROM plant_detail where id = " + ddlEmployees.SelectedItem.Value).Rows[0]; ;
    Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
    Font NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);

    BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIALUNI.TTF", BaseFont.IDENTITY_H, true);

    using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
    {
        PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
        Phrase phrase = null;
        PdfPCell cell1 = null;
        PdfPTable table = null;
        Color color = null;

        document.Open();

        //Header Table
        table = new PdfPTable(2);
        table.TotalWidth = 500f;
        table.LockedWidth = true;
        table.SetWidths(new float[] { 0.3f, 0.7f });

        //Company Logo
        cell1 = ImageCell("~/images/index.jpg", 30f, PdfPCell.ALIGN_CENTER);
        table.AddCell(cell1);

        string cellText = "कार्यालय";
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
        //Company Name and Address
        phrase = new Phrase();
        iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
        //phrase.Add(new Chunk("कार्यालय कलेक्टर रायपुर\n\n\n\n\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD, Color.RED)));
       // phrase.Add(new Chunk("कार्यालय कलेक्टर रायपुर\n\n\n\n\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD, Color.RED)));
        phrase.Add(new Chunk("\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
        phrase.Add(new Chunk("\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
        phrase.Add(new Chunk("", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
        cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
        cell.VerticalAlignment = PdfCell.ALIGN_TOP;
        table.AddCell(cellText);
    }
}

如何在hindi中获取数据?

1 个答案:

答案 0 :(得分:0)

//phrase.Add(new Chunk("कार्यालय कलेक्टर रायपुर\n\n\n\n\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD, Color.RED)));
// phrase.Add(new Chunk("कार्यालय कलेक्टर रायपुर\n\n\n\n\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD, Color.RED)));
phrase.Add(new Chunk("\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));

我在代码中看不到印地语字体。您需要添加Mangal等印地语字体才能显示印地语内容。做一些研究,您可以免费下载。