I am trying to run the PDF generator as a handler since I need to pass parameters from a web URL (not yet added). I know I need to output this as a binary stream but wanted to know if there was an easy way before I tried writing something. I aso just tried saving the PDF and that did not work. Does this code run as a Handler class? My code is below:
public class HelloWorldHandler : IHttpHandler
{
public HelloWorldHandler()
{
}
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
PdfDocument doc = new PdfDocument();
String url = "URL";
Thread thread = new Thread(() =>
{
doc.LoadFromHTML(url, false, true, true);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
doc.SaveToFile("/tempfiles/result.pdf");
doc.SaveToHttpResponse("result.pdf", Response, HttpReadType.Save);
doc.Close();
}
public bool IsReusable
{
// To enable pooling, return true here.
// This keeps the handler in memory.
get { return false; }
}
}
Thanks in advance for your help.
Bob