This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Prompt user whether they want to download pdf

itslincoln wrote on 2016-02-09:
Hi there, I currently have the following code (as per examples):

public static void PDF(){

System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;

// create an API client instance
pdfcrowd.Client client = new pdfcrowd.Client("my username", "my api key");

// convert a web page and write the generated PDF to a memory stream
MemoryStream Stream = new MemoryStream();

client.convertHtml("<head></head><body>My HTML Layout</body>", Stream);

// set HTTP response headers
Response.Clear();
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Cache-Control", "max-age=0");
Response.AddHeader("Accept-Ranges", "none");
Response.AddHeader("Content-Disposition", "attachment; filename=lol.pdf");
// send the generated PDF
Stream.WriteTo(Response.OutputStream);
Stream.Close();
Response.Flush();
Response.End();
}

The code is executed when a button is pressed and i can see that the HTTP POST method is successful. I was just wondering how to view the converted pdf / make it available to download
support wrote on 2016-02-10:
Hello,

If you want to open the generated PDF in the browser, change
Response.AddHeader("Content-Disposition", "attachment; filename=lol.pdf");

to
Response.AddHeader("Content-Disposition", "inline; filename=lol.pdf");
itslincoln wrote on 2016-02-17:
Hi there , I've changed that line but all i receive is what i presume is the encoded pdf in the console like this:

%PDF-1.5
%????
1 0 obj<</Length 220/Filter/FlateDecode>>stream
x?mO?J1?????f?M@?P?75????q}h??~???i[????I???n?Zv?a???????-?^????#?;$??Y? ??NF
?R?.?:????")?R??7,`~p??p?1??j3??&l?gQ?D?=?o????
S?q??8??S??3?OW????\??ZOF$DS??w??T???9??g"????9j?@{?C???

any further ideas on how i could get the download window to pop up would be really appreciated! :)
support wrote on 2016-02-18:
Hello,

If you want to pop up the download dialog, the "attachment" version should do the trick. Could you please post a link to your page which demonstrates the issue?