Question : Sending pdf files to client using webmethods

Hi ,
We are calling a webmethod from the client using getJSON and in the WebMethod we are generating a PDF file as a stream. Now how can I pass it back to the client and show it in the browser.
I know we can save the PDF in some place in the server and then display that in the browser, but I do not want to go to that option. Is it possible to get the byte stream in the client and display it as a PDF in the browser.

Any articles or sample codes or suggestions will be much helpful.

Thanks and regards,
venki

Answer : Sending pdf files to client using webmethods

I can say I know the answer to this but I have to ask why you would need to do this via webmethod when a regular server side event would likely result in the same UI experience.

This is how I do it:

in a button click event:

Response.Clear();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
//can also be "inline" instead of "attachment" to display immediately
Response.AddHeader("Content-Disposition", "attachment; filename=DefaultSaveName.pdf");
//you could also copy bytes to Reponse.OutputStream
Response.WriteFile(@"C:\blah\pdf\mypdf.pdf");
Response.End()

This results in no visible flash or flicker in the browser so I'm not sure what ajax buys you here.

If you are able to do it the ajax way please post how.  I'm curious how you'll get around the browser security.
Random Solutions  
 
programming4us programming4us