Hello
I want to convert an aspx page to PDF using a component that can convert Html to PDF. Is it possible to, during post back, redirect the output from the aspx-page and send it as a stream or string to a HtmlToPdf method?
Hello
I want to convert an aspx page to PDF using a component that can convert Html to PDF. Is it possible to, during post back, redirect the output from the aspx-page and send it as a stream or string to a HtmlToPdf method?
Have you tried to send the value returned from "HttpContext.Current.Response.OutputStream;" in the postback ?
Hi I think that the way to do this would be to use the Reponse.Filter property to intercept and alter the HTML being sent to a page.
There's a tutorial video and sample code in both VB.net and C# on this page on the ASP.net website:
You would write an HttpFilter that is attached to the request. This is code that can change the output after it has been written by the ASP.NET Page's Render step.
This article shows how to do this (they change the output from HTML to valid XHTML, but the idea is the same).
protected override void Render(HtmlTextWriter writer)
{
// setup a TextWriter to capture the page markup
TextWriter tw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(tw);
// render the page into our surrogate TextWriter
base.Render(htw);
// convert the TextWriter markup to a string
string pageSource = tw.ToString();
if (convertToPDF)
{
// convert the page markup to a pdf
// eg, byte[] pdfBytes = HtmlToPdf(pageSource);
}
// write the page markup into the output stream
writer.Write(pageSource);
}