Tuesday, March 13, 2012

the http reponse to file? ASP.NET 2.0

I want to generate a pdf file of "the current page".

It is a ASP.NET aspx file created partly from GET parameters, but most often
using the ASP.NET event model (i.e. clicking buttons etc).

One of the buttons is called "Generate a pdf document of the current page"
and it clicking it should create a pdf document on the server side and
returning the pdf to the user.

To my aid I have a server side component that can convert a file or the html
content of a URL to a pdf document. So if I somehow can generate the
information of the current aspx page to file, I can convert it to pdf and
change the Response.ContentType to "application/pdf".

But the question is how to generate the file that I want to convert. If I
send the current URL to the pdf component, it will point to the page and how
it looks when no interaction has been done. What I really want is the page
after all clicks, i.e. how it looks "right now".

Any ideas? Thank you,

--
/FredrikThus wrote Fredrik,

> I want to generate a pdf file of "the current page".
> It is a ASP.NET aspx file created partly from GET parameters, but most
> often using the ASP.NET event model (i.e. clicking buttons etc).
> One of the buttons is called "Generate a pdf document of the current
> page" and it clicking it should create a pdf document on the server
> side and returning the pdf to the user.
> To my aid I have a server side component that can convert a file or
> the html content of a URL to a pdf document. So if I somehow can
> generate the information of the current aspx page to file, I can
> convert it to pdf and change the Response.ContentType to
> "application/pdf".
> But the question is how to generate the file that I want to convert.
> If I send the current URL to the pdf component, it will point to the
> page and how it looks when no interaction has been done. What I really
> want is the page after all clicks, i.e. how it looks "right now".
> Any ideas? Thank you,

HttpResponse allows you set another stream as a filter using HttpResponse.Filter.
You could use that to write the response to a temporary file, create the
PDF, and write the PDF back to the actual response stream.

Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de
Very interesting!

It seems the file isn't created until the Response ends. This seems natural
to me when thinking about it.

But when the response has ended, I per definition have lost my chance to
alter the response (remeber, I wamt to send the pdf instead). I guess I will
have to trigger another request somehow, and in the new Response show the pdf.

Havn't still figured out the last details yet. Thanks, anyhow, for your kind
help.

Regards

--
/Fredrik

"Joerg Jooss" wrote:

> Thus wrote Fredrik,
> > I want to generate a pdf file of "the current page".
> > It is a ASP.NET aspx file created partly from GET parameters, but most
> > often using the ASP.NET event model (i.e. clicking buttons etc).
> > One of the buttons is called "Generate a pdf document of the current
> > page" and it clicking it should create a pdf document on the server
> > side and returning the pdf to the user.
> > To my aid I have a server side component that can convert a file or
> > the html content of a URL to a pdf document. So if I somehow can
> > generate the information of the current aspx page to file, I can
> > convert it to pdf and change the Response.ContentType to
> > "application/pdf".
> > But the question is how to generate the file that I want to convert.
> > If I send the current URL to the pdf component, it will point to the
> > page and how it looks when no interaction has been done. What I really
> > want is the page after all clicks, i.e. how it looks "right now".
> > Any ideas? Thank you,
> HttpResponse allows you set another stream as a filter using HttpResponse.Filter.
> You could use that to write the response to a temporary file, create the
> PDF, and write the PDF back to the actual response stream.
> Cheers,
> --
> Joerg Jooss
> news-reply@.joergjooss.de
>
Thus wrote Fredrik,

> Very interesting!
> It seems the file isn't created until the Response ends. This seems
> natural to me when thinking about it.

Are you sure you just don't need a Response.Flush()?

Cheers,
--
Joerg Jooss
news-reply@.joergjooss.de

0 comments:

Post a Comment