function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sravan R PinnintiSravan R Pinninti 

How to customize the name of the PDF while Saving?

Hi,

I have a VF page on which I have a button named "Print". On click of print, the user will be redirected a page which is rendered as PDF. Both these pages use same controller. 

Based on a Boolean value i want the name of the PDF to be changed when user tries to Save the file. RIght now, the file name defualts to the name of the page. I have used Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=AccountReport.pdf' in the constructor and I also tried using this inside a method but both did not satisfy my requirement completely. When I use the above code in constructor, the PDF is downloading even before the page is loaded and if I use the code inside a method the PDF is downloaded directly. 

I do not want the PDF to be downloaded. I just want the name to be dynamic when user tries to Save the PDF? Am I missing something here.

Thank You in advance for your help!!

Regards,
Sravan.
Best Answer chosen by Sravan R Pinninti
Sravan R PinnintiSravan R Pinninti

Hi Ramu,

I have used Apexpages.currentPage().getHeaders().put('content-disposition', 'inline; filename=Testfilename.pdf'); in the controller and it worked perfectly. 
If the requirement is to download the file use Apexpages.currentPage().getHeaders().put('content-disposition', 'Attachment; filename=Testfilename.pdf');

Thank You for the response.

Regards,

Sravan.

All Answers

Ramu_SFDCRamu_SFDC
Hi Sravan, see if this helps https://success.salesforce.com/ideaView?id=08730000000BqN0AAK
Sravan R PinnintiSravan R Pinninti

Hi Ramu,

I have used Apexpages.currentPage().getHeaders().put('content-disposition', 'inline; filename=Testfilename.pdf'); in the controller and it worked perfectly. 
If the requirement is to download the file use Apexpages.currentPage().getHeaders().put('content-disposition', 'Attachment; filename=Testfilename.pdf');

Thank You for the response.

Regards,

Sravan.

This was selected as the best answer