Rectangle 27 1

http "name" web pdf for better default save filename in Acrobat?


I'm using ASP.NET MVC Framework, so I modified my routes for that controller/action to make sure that the served up PDF file is the last part of the location portion of the URI (before the query string), and pass everything else in the query string.

If you're taking the filename from a user input on a form, then that should be validated not to contain escaped characters, which will annoy users.

In order for the filenames to look decent, they shouldn't have any escaped characters (ie, no spaces, etc)... which is a bit limiting. My filenames are auto-generated in this case, and before had spaces in them, which were showing up as '%20's in the resulting save dialog filename. I just replaced the spaces with underscores, and that worked out.

The resulting header looks exactly like what you've described (content-type is application/pdf, disposition is inline, filename is uselessly part of the header). Acrobat shows it in the browser window (no save as dialog) and the filename that is auto-populated if a user clicks the Acrobat Save button is the report filename.

This is by no names the best solution, but it does work. It also means that you have to have the filename available to make it part of the original URI, which might mess with your program's workflow. If it's currently being generated or retrieved from a database during the server-side call that generates the PDF, you might need to move the code that generates the filename to javascript as part of a form submission or if it comes from a database make it a quick ajax call to get the filename when building the URL that results in the inlined PDF.

Note
Rectangle 27 1

http "name" web pdf for better default save filename in Acrobat?


Awesome, I've been searching all over the internet for this feature and this is the place that I have found it. Thanks.

Note
Rectangle 27 1

http "name" web pdf for better default save filename in Acrobat?


private void DownloadSharePointDocument()
{
    Uri uriAddress = new Uri("http://hyddlf5187:900/SharePointDownloadService/FulfillmentDownload.svc/GetDocumentByID/1/drmfree/");
    HttpWebRequest req = WebRequest.Create(uriAddress) as HttpWebRequest;
    // Get response   
    using (HttpWebResponse httpWebResponse = req.GetResponse() as HttpWebResponse)
    {
        Stream stream = httpWebResponse.GetResponseStream();
        int byteCount = Convert.ToInt32(httpWebResponse.ContentLength);
        byte[] Buffer1 = new byte[byteCount];
        using (BinaryReader reader = new BinaryReader(stream))
        {
            Buffer1 = reader.ReadBytes(byteCount);
        }
        Response.Clear();
        Response.ClearHeaders();
        // set the content type to PDF 
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "attachment;filename=Filename.pdf");
        Response.Buffer = true;
        Response.BinaryWrite(Buffer1);
        Response.Flush();
       // Response.End();
    }
}
  • Read the byte arrary from stream with correct byte length on the basis of stream length.
  • Return Stream with correct array size from service

File download dialog (PDF) with save and open option

Here is the code for read stream and open the File download dialog for PDF file

Note
Rectangle 27 1

http "name" web pdf for better default save filename in Acrobat?


Also, as far as I can tell, the only UA that actually uses the filename for type=inline is Firefox (see test case).

Finally, it's not obvious that the plugin API actually makes that information available (maybe someboy familiar with the API can elaborate).

Is there a solution/work around to this problem?

Part of the problem is that the relevant RFC 2183 doesn't really state what to do with a disposition type of "inline" and a filename.

Related: see attempt to clarify Content-Disposition in HTTP in draft-reschke-rfc2183-in-http -- this is early work in progress, feedback appreciated.

That being said, I have sent a pointer to this question to an Adobe person; maybe the right people will have a look.

Update: I have added a test case, which seems to indicate that the Acrobat reader plugin doesn't use the response headers (in Firefox), although the plugin API provides access to them.

Note
Rectangle 27 1

http "name" web pdf for better default save filename in Acrobat?


<add verb="*" path="/CustomName/*.ashx" type="ITextMiscWeb.MyDocumentHandler"/>
<httpHandlers>  
<add verb="*" path="MyDocument_*.ashx" type="ITextMiscWeb.MyDocumentHandler"/>
  • create a class that implements IHttpHandler
  • map an handler in web.config bounded to the class

If you use asp.net, you can control pdf filename through page (url) file name. As other users wrote, Acrobat is a bit s... when it choose the pdf file name when you press "save" button: it takes the page name, removes the extension and add ".pdf". So /foo/bar/GetMyPdf.aspx gives GetMyPdf.pdf.

Mapping1: all pages have a common radix (MyDocument_):

Mapping2: completely free file name (need a folder in path):

The only solution I found is to manage "dynamic" page names through an asp.net handler:

Note
Rectangle 27 1

http "name" web pdf for better default save filename in Acrobat?


MySaveAsFileName.pdf
http://www. server.com/DocServe.aspx?DocId=XXXXXXX
http://www. server.com/DocServe.aspx/MySaveAsFileName?DocId=XXXXXXX

However, you have to restrict the allowed characters in MySaveAsFileName (no periods, etc.).

In ASP.NET 2.0 change the URL from

Note