1
public PDFFormFillerResult CreateHtmlToPdfMemoryStream(string sHtmlText)
    {
        //Create a stream that we can write to, in this case a MemoryStream
        using (var ms = new MemoryStream())
        {
            //Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF
            var doc = new iTextSharp.text.Document();

            //Create a writer that's bound to our PDF abstraction and our stream
            var writer = PdfWriter.GetInstance(doc, ms);

            //Open the document for writing
            doc.Open();

            var example_html = sHtmlText;

            //Create a new HTMLWorker bound to our document
            var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc);

          FontFactory.Register(Path.Combine(Environment.CurrentDirectory + "\\Library\\arial.ttf"), "Arial");   // just give a path of arial.ttf
            StyleSheet css = new StyleSheet();
            css.LoadTagStyle("body", "face", "Garamond");
            css.LoadTagStyle("body", "encoding", "Identity-H");
            css.LoadTagStyle("body", "size", "12pt");

            htmlWorker.SetStyleSheet(css);
           // htmlWorker.StartDocument();

            //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses)
            using (var sr = new StringReader(example_html)) // using (TextReader sr = new StreamReader(example_html, Encoding.UTF8))
            {
                //Parse the HTML
                htmlWorker.Parse(sr);
            }

            doc.Close();
            return new PDFFormFillerResult(ms, PDFFormFillerResultType.Success, string.Empty);
        }
    }

I need the output as ByteStream as I am merging multiple documents to create one pdf at the end. This works well for English, but when I try using other languages like Russian, Korean, Combodian, etc only the english text which are in template gets displayed.

Ravi Vanapalli
  • 9,805
  • 3
  • 33
  • 43
  • 1
    You are using `HTMLWorker` instead of XML Worker. `HTMLWorker` is no longer supported; it doesn't support Unicode, etc... (This has been repeated many, many times in many, many questions.) XML Worker can deal with UNICODE. See for instance [hero.pdf](http://itextpdf.com/sites/default/files/hero.pdf) with Chinese glyphs. This document was generated with [XML Worker](http://itextpdf.com/sandbox/xmlworker). – Bruno Lowagie Sep 18 '15 at 12:55
  • @BrunoLowagie , at present the existing code make use of this code and we have got requirement to generate pdf in different languages. Do you suggest to move to XML worker or try using HTMLWorker with some alternate way. – Ravi Vanapalli Sep 18 '15 at 13:03
  • All development on `HTMLWorker` has been abandoned many years ago in favor of XML Worker. If you have invested in using `HTMLWorker`, then that investment is lost (we've warned about this on many places). Move to XML Worker. All time spent on trying to make `HTMLWorker` work will be lost. – Bruno Lowagie Sep 18 '15 at 13:22
  • @BrunoLowagie can you help me with the question asked at http://stackoverflow.com/questions/33234918/generate-pdf-using-itextsharp-for-different-languages , I have upgraded to XML worker. – Ravi Vanapalli Oct 20 '15 at 12:00
  • 1
    I'm at the PDF Technical Conference. I don't have time to answer: I have a talk and I'm a panel member in two panel sessions. However: the problem you report is **very well documented**. You can solve your problem yourself by reading more about implementing a `FontProvider` (e.g. in [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html) or [the sandbox](http://itextpdf.com/sandbox/xmlworker)). – Bruno Lowagie Oct 20 '15 at 17:12
  • Thanks @BrunoLowagie for the help. – Ravi Vanapalli Jan 21 '16 at 13:40

0 Answers0