itextsharp XMLWorkerHelper is very slow to convert the pdf

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

itextsharp XMLWorkerHelper is very slow to convert the pdf

merbin2012
I want to convert html to pdf for many employees payslip, but when the XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, ms, System.Text.Encoding.UTF8); line execute this take more time for execution. my code is shown below, please help me per pdf payslip it take more than 10seconds.





        MemoryStream ms = new MemoryStream();
        iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10f, 10f, 50f, 20f);

        string strBody = hdntblAll.Value;
        MemoryStream memStream = new MemoryStream();

        byte[] byteArray;

            var output = new MemoryStream();
            PdfWriter writer = PdfWriter.GetInstance(document, memStream);

            document.Open();

            string[] separator1 = new string[] { "<br><br><br>" };
            string[] pages = strBody.Split(separator1, StringSplitOptions.None);


            int i = 0;

            foreach (string page in pages)
            {
                if (page != "")
                {
                    i++;
                    document.NewPage();

                    string temppage = "<style>th{font-size:12px;} td{font-size:11px;}</style>" + page;
                    temppage = temppage.Replace("px", "");
                    temppage = temppage.Replace("<br>", "<br/>");

                    byteArray = System.Text.Encoding.UTF8.GetBytes(temppage);
                    ms = new MemoryStream(byteArray);

                    XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, ms, System.Text.Encoding.UTF8);

                }

            }
            document.Close();


            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(memStream.ToArray());
            Response.End();
            Response.Flush();
Loading...