Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Performance Issue for HTML to PDF Conversion using Apose PDF

$
0
0
Hi,

we are using a lincesed version Aspose PDF for HTML to PDF conversion. For this conversion it is taking, in most of the cases, more than 1 minute, which is not acceptable for day to day usage.

Following the source code we are using for HTML to PDF conversion.

 Aspose.Pdf.License license = new Aspose.Pdf.License();
                license.SetLicense("d:\\xxxxx\\Aspose.Pdf.lic");
                // Instantiate an object PDF class
                Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
                // add the section to PDF document sections collection
                Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
                // Create Header Section of the document
                Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(section);

                //Create Footer Section of the document  
                Aspose.Pdf.Generator.HeaderFooter footer = new Aspose.Pdf.Generator.HeaderFooter(section);

                Aspose.Pdf.Generator.MarginInfo marginInfo = new Aspose.Pdf.Generator.MarginInfo();
                marginInfo.Left = 30;
                section.PageInfo.Margin = marginInfo;
                // set the Odd Footer for the PDF file
                section.OddFooter = footer;
                // Set the Even Footer for the PDF file
                section.EvenFooter = footer;
                // set the Odd header for the PDF file
                section.OddHeader = header;
                // Set the Even Header for the PDF file
                section.EvenHeader = header;
       
                Aspose.Pdf.Generator.Text txt = new Aspose.Pdf.Generator.Text(section, headerText.ToString());
                Aspose.Pdf.Generator.Text txtFooter = new Aspose.Pdf.Generator.Text(section, FooterText.ToString());
                //txt.IfHtmlTagSupportedOverwriteHtmlFontNames = true;
                txt.UseTextInfoStyle = true;
                txt.Margin.Bottom = 5;
                txt.Margin.Top = 50;
                txt.Margin.Left = 1;
                txt.TextInfo.FontSize = 9;
                txt.TextInfo.IsTrueTypeFontBold = true;
                txt.TextInfo.FontName = "Arial";


                txtFooter.Margin.Bottom = 5;
                txtFooter.Margin.Top = 20;
                txtFooter.Margin.Left = 30;
                txtFooter.TextInfo.FontSize = 8;
                txtFooter.TextInfo.IsTrueTypeFontBold = true;
                txtFooter.TextInfo.FontName = "Arial";


                // Add text to Header section of the Pdf file                
                header.Paragraphs.Add(txt);

                // Add text to Footer section of the Pdf file                
                footer.Paragraphs.Add(txtFooter);

                // Read the contents of HTML file into StreamReader object
                StreamReader r = File.OpenText(strTemplateRead);
                //Create text paragraphs containing HTML text
                Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
                // enable the property to display HTML contents within their own formatting
                text2.IsHtmlTagSupported = true;
                //Add the text paragraphs containing HTML text to the section
                section.Paragraphs.Add(text2);

                Context.Response.ClearHeaders();
                Context.Response.ContentType = "application/pdf";
                Context.Response.Clear();
                Context.Response.AppendHeader("Content-Disposition", "attachment");
                pdf.Save("NewDoc.pdf", Apdf.SaveType.OpenInBrowser, Context.Response);
                r.Close();
                Context.Response.Close();

Also attaching HTML for sample.

Saw lot of post on performance issues for HTML to PDF conversion.
Please suggest how it could be improved.

 
Thanks
Dinesh

Viewing all articles
Browse latest Browse all 3131

Trending Articles