Print Page | Close Window

Streaming the PDF document directly to the browser

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2411
Printed Date: 04 Apr 26 at 11:46PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Streaming the PDF document directly to the browser
Posted By: Halv
Subject: Streaming the PDF document directly to the browser
Date Posted: 20 Sep 12 at 10:50PM
Greetings,

As the subject says, I found the FAQ for "Streaming the PDF document directly to the browser" and trying to get this to work in C#/ASP. The code works but when I click on the button to generate the PDF it brings up a window to save the PDF file instead of streaming the document directly to the browser. This is what I am using.

qp.CompressContent();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf");
Response.BinaryWrite(qp.SaveToVariant());
Response.End();

I want this to stream the PDF to the browser. If anyone could help me out I would greatly appreciate it.

Halv



Replies:
Posted By: AndrewC
Date Posted: 21 Sep 12 at 3:08AM
I assume you are using the ActiveX version of Quick PDF Library.

According to this your approach is correct..

http://stackoverflow.com/questions/1907758/displaying-a-pdf-document-in-asp-net-page - http://stackoverflow.com/questions/1907758/displaying-a-pdf-document-in-asp-net-page

I have no experience with ASP.net but they are writing their data to Reponse.OutputStream ?  Your code looks like it should work also.

Andrew.


Posted By: samb
Date Posted: 24 Sep 12 at 5:46PM
I believe the important part is changing attachment to inline in Content-Disposition.  Not sure if all the flushing and clearing is required, but this is what I have used in the past and it seems to work ok.

Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline;filename=" + fileName);
Response.AddHeader("Content-Length", fileContents.Length.ToString());
Response.Flush();
Response.BinaryWrite(fileContents);


Posted By: Halv
Date Posted: 25 Sep 12 at 1:39AM
Greetings,

Thanks samb! Your line of code got it working the way I wanted so now the PDF file shows up on the browser instead of prompting to save.

Regards,

Halv



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk