Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I change the default PDF name?

Navigate to "Info" > Click on "Properties" > Double click on "Advanced Properties". You should see a properties dialog box appear. You can then proceed to amend the document metadata such as the Title, author, etc. If you leave the Title field blank, the file name will be reflected in the header instead.

Why is my PDF saving as a different name?

A PDF can be configured to show either the "File Name" or "Document Title" in the title bar. When the title is different from your File Name, it is very likely that you have set your display to "Document Title".

How do I change the PDF title that appears in the browser?

Open the PDF document in Adobe Acrobat Pro: Select File > Properties. Select the Description tab to view the metadata in the document, including the document information dictionary. Modify the Title field to add or change the document's Title entry.


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.

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).

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

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

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.


Set the file name in ContentType as well. This should solve the problem.

context.Response.ContentType = "application/pdf; name=" + fileName;
// the usual stuff
context.Response.AddHeader("content-disposition", "inline; filename=" + fileName);

After you set content-disposition header, also add content-length header, then use binarywrite to stream the PDF.

context.Response.AddHeader("Content-Length", fileBytes.Length.ToString());
context.Response.BinaryWrite(fileBytes);

Like you, I tried and tried to get this to work. Finally I gave up on this idea, and just opted for a workaround.

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.

Eg:

Old URI:

http://server/app/report/showpdf?param1=foo&param2=bar&filename=myreport.pdf

New URI:

http://server/app/report/showpdf/myreport.pdf?param1=foo&param2=bar

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.

A few considerations:

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.

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.

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.

Hope that helps.


Try placing the file name at the end of the URL, before any other parameters. This worked for me. http://www.setasign.de/support/tips-and-tricks/filename-in-browser-plugin/


In ASP.NET 2.0 change the URL from

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

to

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

This works for Acrobat 8 and the default SaveAs filename is now MySaveAsFileName.pdf.

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