Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

c# - Generate pdf using iTextSharp for different languages

I have tried different options, but it did not work. The code generated pdf for English but does not work for other languages.

using (var ms = new MemoryStream())
            {
                // Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF
                var doc = new 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();

                        string finalHtml = string.Empty;

                        // Read your html by database or file here and store it into finalHtml e.g. a string
                        // XMLWorker also reads from a TextReader and not directly from a string
                        using (var srHtml = new StringReader(sHtmlText))
                        {
                            // Parse the HTML
                            iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml);
                        }                            
                        doc.Close();
                    }
                }

                // After all of the PDF "stuff" above is done and closed but **before** we
                // close the MemoryStream, grab all of the active bytes from the stream
                return new PDFFormFillerResult(ms, PDFFormFillerResultType.Success, string.Empty);
                //bytes = ms.ToArray();
            }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well we had to buy another 3rd party tool which understands UNICODE characters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...