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
SFDC 18SFDC 18 

Lightning button for a VF page which renders a PDF

I have written a lightning cmp and controller for a button which calls a VF pagw which renders PDF

CMP
<aura:component implements="force:lightningQuickAction" >
   <lightning:button label="PDF" 
        onclick="{!c.PDF}" />
</aura:component>

Controller :
/* Component controller */
({
 PDF : function(sforce.one.navigateToURL('/apex/Letter?Parameter1=data1'));

})

I'm unable to save my controller as its throwing an error msg

VF page
<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">
<head>
<style>
body { font-family: 'Arial Unicode MS'; }

@page{
    size: letter;
    margin:10%;
    @top-left{
        content: "Dear,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 12px;
    }
    @bottom-right{
        content: "Yours Sincerely,";
        font-family: Helvetica, Arial, sans-serif;
        font-size: 10px;
    }
}

body {
        font-family: Helvetica, Arial, sans-serif;
        font-size: 11px;
}
    </style>
</head>
    <div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
<center>
    <h1> Letter</h1>
    </center>
    <p>{!custom_object__C.Name__C}</p>    
</apex:page>

​Custom Button:


window.open("apex/Letter?Id={!Letter__c.Id}","_blank");
Best Answer chosen by SFDC 18
SFDC 18SFDC 18

Thanks. 
I just changed my cmp code where I have used handle.click for my button, record.ID attribute for the page ID and have written a JS for my handle.click and record.ID in controller.
 

Then I have created a quick action for the button

All Answers

Akshay_DhimanAkshay_Dhiman
Hi SFDC,

    Try for this code.

    ========================== VF Page ===================================
    
<apex:page controller="VF_Page_to_PDFControler2" renderAs="pdf" >
        <apex:form >
            <apex:pageBlock mode="maindetail">
                <apex:pageBlockSection columns="3">
                    <apex:pageBlockSectionItem >
                        <h1 style="width:150px;"/>
                        {!$Organization.Name} <br/>
                        {!$Organization.Street} <br/>
                        {!$Organization.City} <br/>
                        {!$Organization.State} <br/>
                        {!$Organization.PostalCode} <br/>
                        {!$Organization.Country} <br/>
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <h1 style="width:350px;"/>
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <apex:image url="{!URLFOR($Resource.CALogo, 'CALogo.jpg')}" width="200" height="100" />
                    </apex:pageBlockSectionItem>
                </apex:pageBlockSection>
                <hr/><br/>
                <apex:pageBlockSection columns="3">
                    <apex:pageBlockSectionItem >
                      <h5 style="font-size:20px;color:blue;width:150px;">{!accAddress.name}</h5>
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <h1 style="width:370px;"/>
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        {!accAddress.BillingCity }<br/>
                        {!accAddress.BillingState}<br/>
                        {!accAddress.BillingPostalCode}<br/>
                        {!accAddress.BillingCountry}
                    </apex:pageBlockSectionItem>
                    <br/><br/>
                </apex:pageBlockSection>
                <h3 style="background-Color:red;color:white;">{!conformation}</h3>
                <table border="1">
                    <tr style="background-color:blue;">
                        <th  style="width:370px;">LastName</th>
                        <th style="width:370px;">Email</th>
                        <th style="width:370px;">BirthDate</th>
                        <th style="width:370px;">Fax</th>
                    </tr>
                    
                    <apex:repeat value="{!ContactDetails}" var="con">
                        <tr>
                            <td style="width:370px;">{!con.lastname}</td>
                            <td style="width:370px;">{!con.email}</td>
                            <td style="width:370px;">{!con.Birthdate}</td>
                            <td  style="width:370px;">{!con.fax}</td>
                        </tr>
                    </apex:repeat>
                    
                </table>
                
            </apex:pageBlock>
        </apex:form>
    </apex:page>

    ========================== controller ===================================


    public class VF_Page_to_PDFControler2 
    {
        public List<Contact> ContactDetails{get;set;}
        public Account accAddress{get;set;}
        Public String conformation{get;set;}
        public VF_Page_to_PDFControler2()
        {
            ContactDetails=new List<Contact>();
            accAddress=new Account();
           // id myid= ApexPages.currentPage().getParameters().get('id');
            accAddress=[select name,BillingCity,BillingCountry,BillingPostalCode,BillingState from account limit 1];
           List<Contact> conList=new List<contact>([select lastname,Birthdate,email,fax from contact where accountid=:myid ]);
            if(conList.size()>0)
            {
                 ContactDetails=conList;
                 conformation='';
            }
            else{
                conformation='No Any Contacts';
            }
        }
        
    }

If you found this answer helpful then please mark it as best answer so it can help others.

Thank You
Akshay 
SFDC 18SFDC 18

Thanks. 
I just changed my cmp code where I have used handle.click for my button, record.ID attribute for the page ID and have written a JS for my handle.click and record.ID in controller.
 

Then I have created a quick action for the button

This was selected as the best answer
D VelD Vel
SDFC18 can you please share the component and controller