Does anybody done pdf generation by means of LWC(with Visualforce page). I have done following code and it is working fine, until renderAs comes. If anybody knows a solution/workaround, please let me know. PFB code snippet below:

LWC - helloWorld

    Hello World

helloWorldApp - for dependency

<aura:application access="GLOBAL" extends="ltng:outApp"> 
    <aura:dependency resource="c:helloWorld"/>

HelloWorldPdf - Visualforce page

<apex:page renderAs="PDF">
    <apex:includeLightning />

    <div id="lightning" />

        $Lightning.use("c:helloWorldApp", function() {
          $Lightning.createComponent("c:helloWorld",     {}  ,       
              function(cmp) {
                // do some stuff

The PDF renderer does not support JavaScript, but Aura and LWC components are always loaded via JavaScript. That means it is impossible to use renderAs to render an Aura Component or LWC component in to a PDF. There is no workaround to this limitation. You'll need to write the full code in Visualforce if you want to be able to render the page as a PDF.

  • I got a link, which works for smaller text(by pushing text to vf page at runtime) - gist.github.com/toanshulverma/16244d19ac68364cb75443695d81403b However this is not a full-proof solution(and restricted to 135Kb(view state)),
    – Ysr Shk
    Oct 4 '19 at 4:28
  • Since it is not directly possibly by W20, marking this answer as accepted. thanks for your time!
    – Ysr Shk
    Oct 4 '19 at 4:28
  • 1
    @YsrShk Actually, the view state doesn't need to be limited to 135k if you're clever with the design, but in principle, you still wouldn't be able to render Lightning Components this way, because the renderer doesn't support custom components, either, only plain HTML. Hopefully, we'll get a solution in the future, but for now, Visualforce is what we're left with.
    – sfdcfox
    Oct 4 '19 at 13:47
  • Understood the crux(with lightning components). Hope so, we'll get a new PDF generation tool (since old one has lots of limitations).
    – Ysr Shk
    Oct 4 '19 at 14:53

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.