Click here to Skip to main content
12,823,639 members (51,462 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


14 bookmarked
Posted 12 Aug 2008

An intermediate way to generate Indic PDFs using iText/iTextsharp

, 18 Aug 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
All about generating PDF files for Indic scripts using iText/iTextSharp.
This is an old version of the currently published article.


I am working/dealing with Indic scripts for my project and I got so many problems due to partial/no support given by the s/w's or Libraries/Languages/Frameworks. I tried to resolve my problems. One of them is generating PDF's dynamically.

You know iTextSharp is a wonderful library for generating PDf Files dynamically. It supports unicode but not Indic Scripts. iText/iTextSharp has ready answer for this problem/bug/non support but not solution. I am not criticising iText/iTextsharp. Because it's open source one can imporve it.

Background and Terms

I assume you have very basic idea/familier of iText/iTextSharp and GIST and these terms ISCII,Unicode,IsFoc.

My Intermediate Solution

Going Back to History.
I used GIST(Developed by CDAC) and ISCII.

  • Step1:
    • First you have to Convert the Unicode HTML String to ISCII HtmlString .
  • Step2:
    • Convert the ISCII string to ISFOC and Send this string to the iText HtmlParser
  • Step2 and Step3 can be merged by directly Converting Unicode string to ISFoc.This method is exposed by GIST. Can refer the GIST documentation
  • Step3:
    • Publish Pdf generated.


   public static string UniCode2ISCII(string  S)

    if (S == null) { return null; }
        Encoding encFrom = Encoding.GetEncoding(57002);//Hindi
        //Encoding encFrom = Encoding.GetEncoding(57005);//Telugu

        Encoding encTo = Encoding.GetEncoding(1252);
        string str = S;
        Byte[] b = encFrom.GetBytes(str);
        return encTo.GetString(b);
    catch { return null; }


Public Class ISCII2ISFOC
     Declare Function Iscii2Isfoc Lib "ismapi32.dll" (ByVal s1 As String,
         ByVal s2 As String, ByVal ilen As Integer, ByVal sc As String) As Integer
    'Declare Function Isfoc2Iscii Lib "ismapi32.dll" (ByVal s1 As String,
       '  ByVal s2 As String, ByVal ilen As Integer, ByVal sc As String) As Integer
    'Declare Function Iscii2AccessIsfoc Lib "ismapi32.dll" (ByVal s1 As String,
        ' ByVal s2 As String, ByVal ilen As Integer, ByVal sc As String) As Integer
    ' sc = "DVB"   Devanagari  B-  Bilingial 
    '                      Devanagari (DV - catering to Hindi, Marathi, etc.), 
    '                     Gujarati (GJ), Kannada (KN), Malayalam (ML), Manipuri 
    '                     (MN), Oriya (OR), Punjabi (PN), Tamil (TM), Telugu (TL)  
   Public Function ToIsfoc(ByVal str1 As String,ByVal sc as String ) As String
        Dim stext1 As String
        Dim ilen As Integer
        Dim iret As Integer    
       stext1 = Space(str1.Length * 2) 'I Don't know   why it has to multiplied by 2
        ilen = str1.Length
        iret = Iscii2Isfoc(str1, stext1, ilen, sc)

        ToIsfoc = stext1

    End Function

End Class

Note:Above method is written in VB.Net So you have to Compile it as a seperate library and have to consume it.I tried with C# ref Variables.(Not got fruitful results. Needs to be written in C#.)


 //The  font name depends onthe Target Indic Language.  .. It can be made Dyanmic.
publc  void  PublishPdf(string IsFochtmlString){
        string htmlString = "<html><body><font face=\"DVBSR0XT.ttf\">" +
            IsFochtmlString+ "</font></body></html>";

        HttpRequest Request = System.Web.HttpContext.Current.Request;
        HttpResponse Response = System.Web.HttpContext.Current.Response;
         Response.ContentType = "application/pdf";
        System.IO.MemoryStream m = new System.IO.MemoryStream();
        iTextSharp.text.Document document = new iTextSharp.text.Document();

        iTextSharp.text.pdf.PdfWriter writer =
            iTextSharp.text.pdf.PdfWriter.GetInstance(document, m);
        System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(
            new StringReader(htmlString));

        iTextSharp.text.html.HtmlParser.Parse(document, _xmlr);
        Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
       Response.End();      }


  • Compact and tiny compared with unicode.(Obviously.)


  • It inherit's the all limitations from ISCII .
  • It support's Bilingual Only(i.e. English + the Indic Language).
  • It's not the recommended way/It fails when there are multiple languages (Can overcome by splitting the String but It's difficult at runtime but still one can try. It's possible) because It can't recognize the difference between the languages(Indic).


  • Article Raw Version 1 on 13 Aug 2008


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
No Biography provided

You may also be interested in...


Comments and Discussions

Discussions posted for the Published version of this article. Posting a message here will take you to the publicly available article in order to continue your conversation in public.
Questionismapi32.dll Pin
jk.mehta12-Feb-10 20:40
memberjk.mehta12-Feb-10 20:40 
Generalismapi32.dll Pin
Member 417493427-Mar-09 21:47
memberMember 417493427-Mar-09 21:47 
GeneralRe: ismapi32.dll Pin
swapnil chandankar16-Apr-15 2:46
memberswapnil chandankar16-Apr-15 2:46 
GeneralRe:Help Pin
Member 417493424-Mar-09 21:24
memberMember 417493424-Mar-09 21:24 
Generalismapi32.dll Pin
Member 48506917-Mar-09 19:06
memberMember 48506917-Mar-09 19:06 
Generalhelp me Pin
hanhnd846-Feb-09 16:04
memberhanhnd846-Feb-09 16:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 18 Aug 2011
Article Copyright 2008 by Dileep.M
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid