We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Stream Pdf from memory to browser

Hi guys,

I’m creating a pdf in memory and stream this pdf back to the client’s browser.

Everything works fine, except: I do not want the browser’s Save dialog to come up. I would prefer if the pdf would be displayed in the current browser window immediately.

Here is my code:

protected void Page_Load(object sender, EventArgs e)
{
// Merge some files to one single pdf file (MemoryStream)
MemoryStream PdfStream = PdfFactory.MergeFilesToPdf(myFiles);
if (PdfStream == null)
return;

// Stream the pdf back to the client browser
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Charset = “UTF-8”;
Response.AddHeader(“Content-Length”, PdfStream .Length.ToString());
Response.AddHeader(“content-disposition”, String.Format(“attachment;filename={0}”, “Interview.pdf”));
Response.ContentType = “application/pdf”;
Response.BinaryWrite(PdfStream .ToArray());
Response.Flush();
Response.End();
}

I copied this code from http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/sending-pdf-to-browser-over-ssl.html (yes, we are using SSL).

Any idea?

Thanks for your help!
Ingmar



Hello Ingmar,

Thanks for using our products.

Please comment out Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "Interview.pdf")); and add the following code line to display the PDF in web browser rather than displaying the Save dialog box.

Response.AddHeader("Accept-Header", PdfStream.Length.ToString());

In case it does not resolve your problem or you have any further query, please feel free to contact.