{!PDFData} App: thanks in advance", "answerCount": 8, "upvoteCount": 0, "datePublished": "2018-10-10T10:23:08.000Z", "author": { "@type": "Person", "name": "Shaik Galeeb Saheb", "url": "https://trailblazers.salesforce.com/profileView?u=0053000000BePy8AAF", "affiliation": { "@type": "Organization", "name": "--" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Hey all, we can use Blob.toPDF to generate a PDF in Apex and download it using the Lightning component.      Refer to the post.  How to Use Apex for Effective PDF Document Generation and   Generate PDF using jsPDF in Lightning Web Component for step-by-step instructions and a guide.    Thank you,  Dhanik", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4E4mSAF", "datePublished": "2026-09-11T16:35:35.000Z", "author": { "@type": "Person", "name": "Dhanik Sahni", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000DhjH7QAJ", "affiliation": { "@type": "Organization", "name": "SalesforceCodex" } } } ] } } Skip to main content
Shaik Galeeb Saheb a posé une question dans #Lightning Experience
Dear Community,

I am new to Lightning experience,i have some knowledge about lightning.i tried to generate the pdf for Account or any standard or custom object.i wrote the some logic the pfd is generated with empty sheet,i want all the fields of the perticular object which is i mentioned.i think i missed some logic in my components/controllers.

can any one suggest where i did mistake and also can tell me how to generate the pdf for perticular object either custom or standard

my code is 

Apex class:

public class DataDisplayController {

    public String PDFData{get;set;}

    

    public DataDisplayController(){

        

        PDFData = '';

    }

    public PageReference downloadPDF(){

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

        //ensure pdf downloads and is assigned with defined name

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

        

        return pageRef;

    }

    }

Component:

<aura:component >

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

    <lightning:button label = "Download Document" onclick = "{!c.downloadDocument}" />

    

</aura:component>

client-side controller.js

({

 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(){

              

  });

 }

})

Helper.js

({

    helperMethod : function(component,callbackMethod) {

        var action = component.get("c.download");

        action.setCallback(this,function(response){

            var state = response.getState();

            if(state === "SUCCESS"){

                var generatePdf = reponse.getReturnValue();

                component.set("v.sendData",generatePdf);

                console.log('pdf generated successfully');

                

            }

            else{

                console.log('unable to generate the pdf');

            }

        });

        $A.enqueueAction(action);

        

    }

})

VF Page:

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

    <apex:includeLightning />

    

    <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:LightningPDFGeneratorDemoApp", function() {

                $Lightning.createComponent("c:DataProcessor",

                { 

                    sendData : saveData

                },

                "lightning",

                function(cmp) {

                    // do some stuff

                });

            });

        }

        

        loadComponents();

        </script>            

           </apex:form>

</apex:page>

<apex:page controller="DataDisplayController"  renderAs="pdf">

    {!PDFData}

</apex:page>

App:

<aura:application extends = "ltng:outApp" >

    <c:DataProcessor />

    

</aura:application>

thanks in advance
8 réponses
0/9000