Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open pdf in browser plugin

Tags:

asp.net-mvc

How do I (in my controller) send a pdf that opens in the browser. I have tried this but it only downloads the file (both ie and firefox) without asking.

public ActionResult GetIt()
{
    var filename = @"C:\path\to\pdf\test.pdf";
    // Edit start
    ControllerContext.HttpContext.Response.AddHeader("Content-Disposition", String.Format("inline;filename=\"{0}\"", "test.pdf"));
    // Edit stop
    return File(filename, "application/pdf", Server.HtmlEncode(filename));
}

After adding the edit above it works as it should, thanks.

like image 752
Nifle Avatar asked Jun 02 '09 11:06

Nifle


1 Answers

You need to set the Content disposition HTTP header to inline to indicate to the browser that it should try to use a PDF plugin if it is available.

Something like: Content-Disposition: inline; filename=test.pdf

Note that you cannot force the use of the plugin, it is a decision made by the browser.

like image 174
Steve Claridge Avatar answered Nov 15 '22 04:11

Steve Claridge