Page2:
controller: public class DataDisplayController { public String PDFData {get; set;} public DataDisplayController(){ // PDFData = ''; } public PageReference downloadPDF(){ System.PageReference pageRef = new System.PageReference('/apex/AccountPdfPage'); //ensure pdf downloads and is assigned with defined name pageRef.getHeaders().put('content-disposition', 'attachment; filename=RWAForm.pdf'); return pageRef; } } Regards, Raju", "answerCount": 2, "upvoteCount": 0, "datePublished": "2021-04-20T15:51:15.000Z", "author": { "@type": "Person", "name": "Nagaraju Chigicherla", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000CxQE9QAN", "affiliation": { "@type": "Organization", "name": "Daimler Truck Innovation Center" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Hi Suraj, My requirement is smilar to First Option and i have tried based on Webstite. But when click on button it is navigating to pdf page but not displaing data . showing empty screen. Regards, Raj", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4TnFSAV", "datePublished": "2021-04-20T18:22:57.000Z", "author": { "@type": "Person", "name": "Nagaraju Chigicherla", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000CxQE9QAN", "affiliation": { "@type": "Organization", "name": "Daimler Truck Innovation Center" } } } ] } } Skip to main content
Hi Team,

I want to generate pdf page using lightning component inside vf page.

I have tried using below code but showing empty pdf file. could please help on this.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

    

    <aura:attribute name="sendData" type="object"/>

    <lightning:recordViewForm recordId="{!v.recordId}" objectApiName="Account">

       

            

       

       

         <div class="slds-wrap slds-text-align_center">

        <lightning:button aura:id="printButton" class="topMargin noPrint" label="Print In Pdf" onclick="{!c.downloadDocument}" />

        </div>

         <div class="slds-wrap slds-text-align_center">

            RWA FORM

        </div>

        <table  class="slds-table slds-table_bordered slds-table_cell-buffer">

            <div class="slds-grid slds-gutters">

                <div class="slds-col">

                    <span>Account⌗⌗</span>

                </div>

                <div class="slds-col">

                    <span> <lightning:outputField variant="label-hidden" fieldName="Name" /></span>

                </div>

                <div class="slds-col">

                    <span>Effective date</span>

                </div>

                <div class="slds-col">

                    <span><lightning:outputField variant="label-hidden" fieldName="Effective_Date__c" /></span>

                </div>

            </div>

            <br/>

        </table>

        <br/>    

    </lightning:recordViewForm>   

</aura:component>

({

    downloadDocument : function(component, event, helper) {

           

        var sendDataProc = component.get("v.sendData");

        var dataToSend = {

           

            "label" : "This is test"

        }; //this is data you want to send for PDF generation

        

        //invoke vf page js method

        sendDataProc(dataToSend, function(){

          window.print();

        });

         

    }

    

})

Page1:

<apex:page controller="DataDisplayController" showHeader="false">

    <apex:includeLightning />

    

    <!-- Page code -->

    <apex:form >

        <apex:inputhidden id="hidData" value="{!PDFData}"/>

    

        <apex:actionfunction name="jsGeneratePDF" action="{!downloadPDF}" />

        

        <div id="lightning" />

        

    <script>

        function saveData(data, callback){

            var hidData = document.getElementById('{!$Component.hidData}');

            hidData.value = JSON.stringify(data);

            

            //invoke PDF Generation

            jsGeneratePDF();

         

            //invoke callback;

            if(typeof callback == 'function') callback();

        }

        

        

        function loadComponents(){

            console.log("Loading lightning component: DataProcessor");

            

            $Lightning.use("c:test", function() {

                $Lightning.createComponent("c:AccountViewForm",

                { 

                    sendData : saveData

                },

                "lightning",

                function(cmp) {

                    // do some stuff

                });

            });

        }

        

        loadComponents();

    </script>

    </apex:form> 

   

</apex:page>

Page2:

<apex:page controller="DataDisplayController" showHeader="false">

    <apex:includeLightning />

    

    <!-- Page code -->

    <apex:form >

        <apex:inputhidden id="hidData" value="{!PDFData}"/>

    

        <apex:actionfunction name="jsGeneratePDF" action="{!downloadPDF}" />

        

        <div id="lightning" />

        

    <script>

        function saveData(data, callback){

            var hidData = document.getElementById('{!$Component.hidData}');

            hidData.value = JSON.stringify(data);

            

            //invoke PDF Generation

            jsGeneratePDF();

         

            //invoke callback;

            if(typeof callback == 'function') callback();

        }

        

        

        function loadComponents(){

            console.log("Loading lightning component: DataProcessor");

            

            $Lightning.use("c:test", function() {

                $Lightning.createComponent("c:AccountViewForm",

                { 

                    sendData : saveData

                },

                "lightning",

                function(cmp) {

                    // do some stuff

                });

            });

        }

        

        loadComponents();

    </script>

    </apex:form> 

   

</apex:page>

controller:

public class DataDisplayController {

    public String PDFData {get; set;} 

    

    public DataDisplayController(){

       // PDFData = '';

    }

    

    public PageReference downloadPDF(){

        System.PageReference pageRef = new System.PageReference('/apex/AccountPdfPage');

        

        //ensure pdf downloads and is assigned with defined name

        pageRef.getHeaders().put('content-disposition', 'attachment; filename=RWAForm.pdf');

        

        return pageRef;

    }

}

Regards,

Raju
2 réponses
  1. 20 avr. 2021, 18:22
    Hi Suraj,

    My requirement is smilar to First Option and i have tried based on Webstite.

    But when click on button it is navigating to pdf page but not displaing data . showing empty screen.

    Regards,

    Raj
0/9000