5

I've got a lightning component who looks like a web page. The user wants a button to print that as PDF.

I didn't find solution, though I did try some things:

  • Build a visualforce page with my embedded lightning component. But I can't render the VFP as PDF with the lightning component because the component is added to page using Javascript and render is before in server.

  • I tried with jsPDF.js library without success.

  • 1
    what did you try with jsPDF and why that failed? and true, lighting is JS rendered, so it can not be used to store on VF page and received by getContent. – kurunve Feb 4 '16 at 13:15
  • You are going to have to figure out a Javascript PDF library that works for you. If you want help from us, you will have to be more specific about what did not work. It may be more appropriate to post on Stack Overflow if the error is not Salesforce-centric. – Adrian Larson Feb 4 '16 at 15:52
  • Hi @Antonio have you got this resolved? I'm looking for similar functionality. Thanks – Pasan Eeriyagama Oct 31 '17 at 1:36
3

Simply use Window.Print() function and add that function to a button click event.

1

I just saw this post and realized I have written a blog post around the same request.

http://www.vermanshul.com/2017/07/lightning-generate-pdf-from-lightning.html

The gist of the post is:-

  • We have in-memory data (data not stored within Salesforce)
  • Lightning component is hosted within a visualforce page
  • Visualforce page stores data in it's viewstate
  • Visualforce page triggers another VF page to generate PDF
  • PDF generated is stored as attachment to a record or can be downloaded

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.