I have been trying to generate simple PDFs from my app so that I can later move on to generating PDF with dynamic data. My code generates the files but I want a way to also have the browser prompt the download of the file.
I actually don’t even want to store generated files on my server but I’m not sure how to get it to just provide it to the user without first storing it in the server drive.
public ActionResult GetPDF()
{
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("../Content/test.pdf"), FileMode.Create));
document.Open();
string strHTML = "<B>I Love ASP.Net!</B>";
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.Parse(new StringReader(strHTML));
document.Close();
return File(document, "application/pdf", Server.HtmlEncode(filename));//this doesnt work, obviously
}
Use a
FileStreamResultAction