We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Conversion timeout when generating PDF

Dear Support,

We use the following SyncFusion method in order to convert HTML from secured web page to PDF:

public Syncfusion.Pdf.HtmlToPdf.HtmlToPdfResult Convert(string url, Syncfusion.HtmlConverter.ImageType type, int width, int height, Syncfusion.HtmlConverter.AspectRatio aspectRatio, string username, string password)

The problem is we sometimes have conversion timeout - it happens occasionally and it does not depend on HTML size (no more than 1-3 Mb). We use STA thread to execute HtmlConverter method. The following code leads to timeout:

            Thread thread = new Thread(threadStart);
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            if (!thread.Join(30000))
            {
                thread.Abort();               
                throw new Exception("Conversion Timeout");
            }

Server settings: Windows 2008 Server, 64bit, IE9/IE8

Could you please assist? 
Looking forward to your reply.

Best regards,
Natalya

8 Replies

HA hatallia June 18, 2012 09:40 AM UTC

Any ideas? Thanks in advance.



GM Geetha M Syncfusion Team June 18, 2012 11:39 AM UTC

Hi Natalya,

Sorry for the delay.

The HTML converter navigates to the specified HTML (a WebBrowser control is been used internally) and converts it to Image. The image conversion starts only after the document completion event is fired. After this, the image is drawn into PDF. The image to PDF conversion always take same time duration for a HTML. However, the document completion depends on download speed, server accessibility etc. Please check this and let me know if you have any questions.

Regards
Geetha


HA hatallia June 18, 2012 02:50 PM UTC

Hi Geetha M,

Thanks for your quick response.

There is no downtime when opening HTML page in IE browser under user account we use to render PDF. Are there any other reasons why thread may hang? Could you please review the following code:

  [STAThread]
public static MemoryStream Convert(byte[] content, string uriString, bool isAttachment, string userName = null, string password = null)
        {
            PdfDocument pdfDocument;

            pdfDocument = new PdfDocument();
            pdfDocument.PageSettings.Orientation = PdfPageOrientation.Portrait;
            PdfPage page = pdfDocument.Pages.Add();

            PdfUnitConvertor convertor = new PdfUnitConvertor();
            float width = -1;
            float height = -1;

            SizeF pageSize = page.GetClientSize();
            width = convertor.ConvertToPixels(pageSize.Width, PdfGraphicsUnit.Point);

            using (HtmlConverter html = new HtmlConverter())
            {
                html.EnableJavaScript = true;
                html.AutoDetectPageBreak = true;
                html.EnableHyperlinks = false;

                
                    using (HtmlToPdfResult result = html.Convert(uriString, ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth, userName, password))
                    {
                        if (result.RenderedImage == null)
                            throw new Exception("Error Randering HTML Image");
                        
                        PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
                        format.Break = PdfLayoutBreakType.FitPage;
                        format.Layout = PdfLayoutType.Paginate;
                        format.SplitTextLines = false;
                        format.SplitImages = true;

                        result.Render(page, format);
                    }
                
                MemoryStream resultStream = new MemoryStream();
                pdfDocument.Save(resultStream);
                return resultStream;
            }
        }

Note, that stream size is no more than 3Mb, therefore it is unclear why it takes so long to execute (we experience 30 sec timeout).

Have you encountered any similar problems with methods HtmlToPdfResult.Render or PdfDocument.Save? Can they cause any memory leaks, etc? Looking forward to your reply.


GM Geetha M Syncfusion Team June 19, 2012 10:54 AM UTC

Hi Natalya,

Thank you for the code snippet.

No, we have not encountered memory leak problem with HTML conversion. Could you please send us HTML as well so that we can check here? You may also create a new direct trac incident with details.

Regards
Geetha


HA hatallia June 19, 2012 12:01 PM UTC

Hi Geetha M,

Thank you for your assistance. 
Please find the original html file with images enclosed.

Kind regards,
Natallia


201206_e71bb8d3.ZIP


GM Geetha M Syncfusion Team June 20, 2012 11:24 AM UTC

Hi Natallia,

Thank you for the details.

I tried to convert the HTML you sent to us and it converted to PDF in 6 seconds with Essential Studio version 10.2. Could you please let us know the Essential Studio version? Also, please send us the following details:

1. OS Version
2. Bit type (32 or 64 bit)
3. IE version

Regards
Geetha


HA hatallia June 20, 2012 12:32 PM UTC

We user 9.1.0.24 version, Windows 2008 Server OS, 64 bit.
Probably, we need to try the latest version of your product.
Thank you.




GM Geetha M Syncfusion Team June 21, 2012 04:18 AM UTC

Hi Natallia,

Thank you for the details.

Please let us know if you have any other questions.

Regards
Geetha

Loader.
Live Chat Icon For mobile
Up arrow icon