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

HTML to PDF Problem! Having timeouts

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:

[WebMethod]

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);

doc.Save("MojPDF.pdf");

doc.Close(true);

}

}

 

Thank you for help!


4 Replies

MJ Maciej Jedrzejewski 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?

MJ



GM Geetha M Syncfusion Team 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:

//WebService
document.Save(ms);
document.Close(true);

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

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

Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/pdf";

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

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

Regards
Geetha


MJ Maciej Jedrzejewski 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!



GM Geetha M Syncfusion Team July 10, 2012 09:09 AM UTC

Hi Maciej,

Thank you for the update.

Please let us know if you have any other questions.

Regards
Geetha

Loader.
Live Chat Icon For mobile
Up arrow icon