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.
Unfortunately, activation email could not send to your email. Please try again.

Conversion timeout when generating PDF

Thread ID:

Created:

Updated:

Platform:

Replies:

104017 Jun 15,2012 05:28 AM Jun 21,2012 12:18 AM ASP.NET Web Forms (Classic) 8
loading
Tags: PDF
hatallia
Asked On June 15, 2012 05:28 AM

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

hatallia
Replied On June 18, 2012 05:40 AM

Any ideas? Thanks in advance.


Geetha M [Syncfusion]
Replied On June 18, 2012 07:39 AM

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

hatallia
Replied On June 18, 2012 10:50 AM

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.

Geetha M [Syncfusion]
Replied On June 19, 2012 06:54 AM

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

hatallia
Replied On June 19, 2012 08:01 AM

Hi Geetha M,

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

Kind regards,
Natallia


201206_e71bb8d3.ZIP

Geetha M [Syncfusion]
Replied On June 20, 2012 07:24 AM

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

hatallia
Replied On June 20, 2012 08:32 AM

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.



Geetha M [Syncfusion]
Replied On June 21, 2012 12:18 AM

Hi Natallia,

Thank you for the details.

Please let us know if you have any other questions.

Regards
Geetha

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;