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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

HTML to PDF Problem! Having timeouts

Thread ID:





104272 Jul 5,2012 01:16 PM UTC Jul 10,2012 09:09 AM UTC ASP.NET Web Forms (Classic) 4
Tags: PDF
Maciej Jedrzejewski
Asked On July 5, 2012 01:16 PM UTC

We have a problem with a webservice while generating a local site. It has a problems with a html converter. Then we wanted to save our website at a local disc, but it is working and working and nothing is done(after using threading). I tried this threads, but they don't help. Here is the code:


public void go()


float itsHeight = -1;

PdfPage itsPage = null;

PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A1B);

doc.PageSettings.Orientation = PdfPageOrientation.Portrait;

itsPage = doc.Pages.Add();

HtmlConverter html = new HtmlConverter();

html.AutoDetectPageBreak = true;

html.EnableHyperlinks = true;

html.EnableJavaScript = true;

PdfUnitConvertor convertor = new PdfUnitConvertor();

float itsWidth = convertor.ConvertToPixels(itsPage.GetClientSize().Width, PdfGraphicsUnit.Point);

HtmlToPdfResult result = html.Convert(textBox1.Text.ToString(), ImageType.Metafile, (int)itsWidth, (int)itsHeight, AspectRatio.KeepWidth);

PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);

mf.Quality = 100;

PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();

format.Break = PdfLayoutBreakType.FitPage;

format.Layout = PdfLayoutType.Paginate;

mf.Draw(itsPage, new PointF(0, 0), format);






Thank you for help!

Maciej Jedrzejewski
Replied On July 6, 2012 12:24 PM UTC

Ok. It was my fault. I tried to use thread in my app, not at this line as it should be. Now everything works fine.

Only one more question:

We use VS 2008, and when I create a web service, i have problem with this line(it works fine in web application):

doc.save(fileName, Response, HttpReadType.Save)

"Response" is not visible, it is impossible to use it. Can I ask why?


Geetha M [Syncfusion]
Replied On July 9, 2012 02:00 PM UTC

Hi Maciej,

Thank you for the details.

I am afraid you cannot make use of HttpResponse in webservice. You can save the PDF in MemoryStream, stream the bytes back to the calling application and then send it via HttpResponse. Here is the code snippet:


ms.Position = 0;
return ms.ToArray();

// From Web application
byte[] file = client.ConvertHTML(url);

Response.ContentType = "application/pdf";

Response.AppendHeader("Content-Disposition", "attachment;filename=Sample.pdf");

Please try this and let me know if you have any questions.


Maciej Jedrzejewski
Replied On July 10, 2012 08:58 AM UTC

Ok, fine. I realised that I had made a few mistakes, but now everything is working fine. Thanks!

Geetha M [Syncfusion]
Replied On July 10, 2012 09:09 AM UTC

Hi Maciej,

Thank you for the update.

Please let us know if you have any other questions.



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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon