Chrome PDF Viewer "Save to disk" function - is it possible to manage a saved file name extension?

In an ASP.NET 2.0 application using Google Chrome 13 on Windows.

My application dynamically generates a PDF report when a user views a particular aspx page. For the most part, everything works fine in different browsers.

However, in Chrome, when using the Chrome PDF viewer, the following may happen: - the user clicks the floating disk icon in the lower right of the viewer to save the PDF. The file is saved with the aspx page name. e.g. Report.aspx.

If I open the downloaded aspx file in Adobe Reader, it will open as a PDF document. But is there a way to get the default chrome filename for saving in order to have the extension β€œ.PDF”?

EDIT:

The code for the report page looks something like this:

protected void Page_Load(object sender, EventArgs e) { Response.Clear(); Response.ContentType = "application/pdf"; byte[] data = GenerateReportHere(); // dynamically generate PDF report Response.AddHeader("Content-Length", data.Length.ToString()); Response.BinaryWrite(data); Response.Flush(); Response.End(); } 

Note that I do not want to use the "Content-Disposition" header, for example:

  Response.AddHeader("Content-Disposition", "attachment; filename=Report.pdf"); 

as this causes the browser to ask the user if he wants to download the file. In Chrome, it does not display it in its PDF viewer - it simply gives the user the option, after downloading, to open the file using any program associated with the .pdf file extension.

+4
source share
2 answers

You should try using the content-disposition header when streaming a PDF file to a browser. For instance,

 HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=[ReportName].pdf"); // Code to stream pdf file content to the client ... 

For more information on posting content, see

+2
source

Since chrome has been updated with HTML5, we can use the new new download attribute!

<a href="http://www.domain.com/painful.pdf" download="newname">Works</a>

+1
source

Source: https://habr.com/ru/post/1369442/


All Articles