I need to view/generate PDF in Lightning component. How can I achieve that?

Do I have to user VF page with "renderAs" attribute inside Lightning Component? Or is there any other way to achieve this?


There are two methods to show a PDF in Lightning Component.

  • First, you can create a Visualforce page and embed it in the Lightning component. See detailed example here

  • Second is, usage of PDF.JS library to directly use lightning component to display the PDF. See details here .Entire source code can be found here.

Let me know if this helps!

| improve this answer | |
  • How can I embed VF page in lightning? I am unable to see any output when I use <iframe> tag to include VF page. – user36778 Jan 18 '18 at 9:23
  • Example at this link didn't help? vermanshul.com/2017/07/… – Hemant Jain Jan 18 '18 at 9:28
  • The link was helpful. But how can I use it in lightning components? The example you mentioned makes use of lightning component in VF page. What I need is to generate/view PDF from lightning component. – user36778 Jan 18 '18 at 11:15
  • What abt second option? – Hemant Jain Jan 18 '18 at 13:17

You can embed a vfPage (renderas="pdf") in lightning component and utilize the component in required place.

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" >
<iframe src="{! '/apex/pdfPage'}" width="100%" height="500px;" frameBorder="0"/>

Hope it helps!

| improve this answer | |

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.