+ Start a Discussion
suneel raosuneel rao 

How to download the PDF in new tab when a button is clicked in custom vfpage

Hi all,
I want to download the PDF in the new tab when a button in custom vfpage is clicked. Can anyone help me over here.
Best Answer chosen by suneel rao
Santosh Sriram 2310Santosh Sriram 2310
Hi Suneel

You can use commandLink instead of a commandbutton. You can use the style attribute to make it look like a button
<apex:commandLink action="{!controllerMethod}" target="_blank" value="Link to Attachment" id="theButton" styleclass="btnImportant"/>

Hope this helps! If you think this resolved your issue, kindly select this as the answer to help the community!

Thanks
Santosh Kumar Sriram


 

All Answers

Onesh ReddyOnesh Reddy
Hi Suneel,
You can use  target="_blank" to redirect to new page on clicking link
<apex:commandbutton value="Link to Attachment" action="{!controllerMethod}" target="_blank"/>

Let me know if it helps you.

Regards,
Onesh.K
suneel raosuneel rao
Hi Onesh,
Thanks for the reply. I have have already tried it. Getting error as
Error: Unsupported attribute target in <apex:commandbutton>
Onesh ReddyOnesh Reddy
Suneel,
Could you post the code for custom vf page, might be easy to help
suneel raosuneel rao
Belwo is the code which i have used in my custom vfpage for PDF.
<apex:commandbutton action="{!getpdfpage}" value="PDF" target="_blank"/>

Method in class:
 public PageReference getpdfpage() {
  this.ugId = ApexPages.currentPage().getParameters().get('id');
  Pagereference ref = new Pagereference('/apex/UG_PDF_Page?id=' +this.ugId);

              ref.setRedirect(true);
            
         // if successfully inserted new lform, then displays the thank you page.
           return ref;      
    }
SFDC Coder 1SFDC Coder 1
Hi Suneel,

It would be great if you will share the Issue in more detail.
Like what issue are you facing and what happens when you clicks the buttons.

Thanks
Santosh Sriram 2310Santosh Sriram 2310
Hi Suneel

You can use commandLink instead of a commandbutton. You can use the style attribute to make it look like a button
<apex:commandLink action="{!controllerMethod}" target="_blank" value="Link to Attachment" id="theButton" styleclass="btnImportant"/>

Hope this helps! If you think this resolved your issue, kindly select this as the answer to help the community!

Thanks
Santosh Kumar Sriram


 
This was selected as the best answer