I'm writing a web application and i want to pass PDF document object o web browser like Chrome, IE, FireFox, Safari, etc. For instance, sending a stream to the client browser and PDF will be created on the fly. In other words, users may chose to click a button and decide whether to download and save the PDF file. That's it. I think this might not be so difficult.
So, how can I send PDF document object to browsers and open/save it as PDF? Or, how can I convert the object to Byte[] stream?
This article on XsPDF.com is what are you looking for, check out: .NET PDF library SDK.
Answers
From what i see, it is not necessary to change the memory steam to byte array. Instead of saving PDF document to a file, you should save it to the Response.OutputStream. Directly create the PDF in memory and then write the memorystream to response.OutputStream.
To be specific, first of all, you need to save the PDF document to a MemoryStream object. You also need to avoid writing anything to the browser before writing the content of PDF. Please set the content type of response stream to PDF mime type. If you want your web application to be user-friendly, you are supposed to add a header to specify the name of PDF file, which will let web browsers bring up the file save dialog box.