开发者

How to embed unicode marathi text in pdf file generated using Asp.net / C# and itextsharp?

        Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

        BaseFont marathi = iTextSharp.text.pdf.BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont开发者_运维百科.EMBEDDED);

        iTextSharp.text.Font fontNormal = new iTextSharp.text.Font(marathi, 12, iTextSharp.text.Font.NORMAL);

        PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
        //Open Document to write
        doc.Open();

        //Write some content
        Paragraph paragraph = new Paragraph("English मराठी English मराठी English मराठी ");

        // Now add the above created text using different class object to our pdf document
        doc.Add(paragraph);


        doc.Close(); //Close document

I am using the above code to generate a PDF file. The generated PDF file only contains the words English and does not contain मराठी.

What needs to be done so that the unicode Marathi strings are included in the pdf?


First, you need a font that has the characters you want. "Helvetica" won't work. Then you need an encoding that can represent those characters. "Identity-H" always works.

Google for itext font samples if you need further infotmation.


Changed the code and it's working now. Used Arial Unicode font. Also while adding text to paragraph, specified the font to be used.

        Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

        BaseFont marathi = iTextSharp.text.pdf.BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED

        iTextSharp.text.Font fontNormal = new iTextSharp.text.Font(marathi, 12, iTextSharp.text.Font.NORMAL);

        PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
        //Open Document to write
        doc.Open();

        //Write some content
        Paragraph paragraph = new Paragraph("English मराठी English मराठी English मराठी ", fontNormal); // --->> CHANGED Specify the font to use

        // Now add the above created text using different class object to our pdf document
        doc.Add(paragraph);

        doc.Close(); //Close document


Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

    BaseFont marathi = iTextSharp.text.pdf.BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED

    iTextSharp.text.Font fontNormal = new iTextSharp.text.Font(marathi, 12, iTextSharp.text.Font.NORMAL);

    PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
    //Open Document to write
    doc.Open();

    //Write some content
    Paragraph paragraph = new Paragraph("English मराठी English मराठी English मराठी ", fontNormal); // --->> CHANGED Specify the font to use

    // Now add the above created text using different class object to our pdf document
    doc.Add(paragraph);

    doc.Close(); //Close document
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜