0

Below is my lightning component which calls a VF Page

<aura:component implements="force:lightningQuickAction" >

   <!-- attribute to accept Visualforce page's javascript method -->
   <aura:attribute name="TTDLetter" type="object"/>

   <!-- Button component to invoke PDF download -->
   <lightning:button label="PDF" 
        onclick="{!c.PDF}" />
</aura:component>

My 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>

For the Lightning component If have created a quick action called "PDF", when I have clicked on PDF button from my object , I got a error stating :

A Component Error has occurred!.

Can anyone just state me where I got my error as i got stuck here

  • normally, there is an actual error message other than "a component error has ocurred" mind sharing it VErbatim? additionally, have you tried anything to troubleshoot? it will help narrow down where you might be getting this error and will help others help you. Additionally, I dont see how your VF page is related to your lightning component – glls Jul 21 '18 at 15:03
0

Before creating your lightning component, have you tried creating a new custom button with a 'Visualforce Page' content source ?

Displaying VF pages rendered as PDF via this button works fine for me in LEX.

You will have to make a few changes to your VF Page in order to make it available for your button :

<apex:page controller="MyController" renderAs="pdf" applyBodyTag="false">

becomes

<apex:page standardcontroller="yourObjectApiName" extensions="MyController" renderAs="pdf" applyBodyTag="false">

I hope this helps you.

  • yes i have a onclick JS button : window.open("apex/Letter?Id={!_Letter__c.Id}","_blank"); – sf123 Jul 21 '18 at 15:22
  • Where should this button appear ? Onclick JS buttons are not supported in LEX – Sohaib FAROOQ Jul 21 '18 at 15:28
  • Yes, this button is for Classic as it doesn't support LEX I have written the lightning action n created a quick action "pdf" for that, but it is unable to generate the PDF which was generated through my VF page – sf123 Jul 21 '18 at 15:33
  • Okay, I understand that you keep your onclick JS button for Classic. Are you trying to access the VF Page to render as a PDF in your component's JS controller ? – Sohaib FAROOQ Jul 21 '18 at 15:37
  • Yes, I'm trying to do that. But I got stuck with this as I'm unable to find out where I got the mistake. The error message was: Uncaught Unknown controller action 'PDF' – sf123 Jul 21 '18 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.