+ Start a Discussion
Arul Bernard I 14Arul Bernard I 14 

How to use command link in pdf page using visualforce page?

I am using "renders - pdf". In that pdf page, I'm using command link and action is not working on the page. How to overcome this issue?
Narender Singh(Nads)Narender Singh(Nads)
Hi,
According to the Visualforce docs, apex:commandLInk is unsafe to use when generating a PDF, which usually means it doesn't work.  

apex:outputLink is documented as safe to use, so you could provide a link back the previous page that way.  You won't be able to post back to the server though.

Thanks!
Arul Bernard I 14Arul Bernard I 14
I tried outputLink. It not even get into page block table?

<apex:form >
    <apex:pageblock id="account" title="Part" >
    
            <apex:pageblockTable value="{!attch}" var="a" >
             
              <apex:column >
              <apex:outputLink title="sample" value="{!URLFOR($Action.Attachment.Download, a.Id)}">{!a.Name}</apex:outputLink>
              </apex:column>
          
           </apex:pageblockTable>
    
         </apex:pageblock>
    </apex:form>
Narender Singh(Nads)Narender Singh(Nads)
Hi Arul,

Take reference from this sample code:
 
VF page
------------
<apex:page standardController="Attachment" extensions="TestCls" renderAs="pdf" >
    
    <apex:form>
        <apex:pageBlock>
            
            <apex:pageBlockTable value="{!AttachmentList}" var="a" >
                <apex:column >
                    <apex:outputLink title="sample"  value="{!URLFOR($Action.Attachment.Download, a.Id)}">{!a.Name}</apex:outputLink>
                </apex:column>
                
            </apex:pageBlockTable>
        </apex:pageBlock>
        
    </apex:form>
    
</apex:page>


Controller
-------------
public class TestCls {
  
    public Attachment[] AttachmentList{get;set;}
    public testcls(ApexPages.standardController std){
        AttachmentList=[select id,name from attachment];
    }

}

Let me know if it helps.
Thanks
Narender Singh(Nads)Narender Singh(Nads)
You can remove the standardcontroller. It is not required.
 
Arul Bernard I 14Arul Bernard I 14
Hi Narender,
It's fine. I have done with vf and class. but while I run the program it's not getting into page block table. Is there any other way overcome 
Narender Singh(Nads)Narender Singh(Nads)
Hi Arul,
To get the data in a tabular form you will have to add your custom css to the VF page. You can use apex:datatable and add your css styling to that.
Narender Singh(Nads)Narender Singh(Nads)
Please mark a best answer if you found my answer helpful so that others with similar issue can benefit from this post.
Thanks