What can I do on a Visualforce page that is a renderAs="pdf" that will result in the name of the file that shows up when the user clicks Save As... to not be the name of the Visualforce page.

The page is generated via a GET request coming from clicking a custom button.

Below is some code that is representative of the PDF.

 <apex:page standardController="Account" extensions="AccountPdf" 
         <apex:outputText value="Hello World"/>

The browser bar does not have the title value in it and when the user clicks Save As... the name of the file is the name of the Visualforce page (e.g., myPageName). If I remove the renderAs="pdf" the file downloads automatically with the correct file name due to the contentType, but the actual content type doesn't appear to be a PDF.

2 Answers 2


You would need to set the Content-Disposition header.

In constructor of the Visualforce controller:

Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=AccountReport.pdf');

If you want to make the file name dynamic you will need to refer to several RFCs on how to correctly encode the filename. E.g. if it contains spaces it will need to be quoted. If there are non-ASCII characters or it is longer than 78 characters it needs to be Hex encoded (RFC 2184).

  • 6
    Just to add another note to this. You can say 'inline; filename=AccountReport.pdf' if you want chrome and other browsers that have built-in PDF support to open them instead of trying to save them. When you do this, you can still save them and it'll pre-populate the filename of 'AccountReport.pdf' Commented Jul 6, 2018 at 17:38
  • Solution was helpful. But when opened the downloaded PDF file it prompted as corrupted. Not sure why the dynamic naming created problem when I used alphanumeric and hyphens to create filename. So used ('content-disposition', 'inline; filename='+myfilename); instead. It worked. Any idea? Commented Mar 18, 2021 at 9:49

This feature is not yet enabled on the <apex:page/> tag in Visualforce, however, you can set the filename in the <messaging:attachment/> tag in Visualforce email templates.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .