2

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

<template>
    Hello World
</template>

helloWorldApp - for dependency

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

HelloWorldPdf - Visualforce page

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

    <div id="lightning" />

    <script>
        $Lightning.use("c:helloWorldApp", function() {
          $Lightning.createComponent("c:helloWorld",     {}  ,       
              "lightning",
              function(cmp) {
                // do some stuff
              }
          );
        });
    </script>
</apex:page>
0

1 Answer 1

6

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.

7
  • 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, 2019 at 4:28
  • Since it is not directly possibly by W20, marking this answer as accepted. thanks for your time!
    – Ysr Shk
    Oct 4, 2019 at 4:28
  • 3
    @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, 2019 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, 2019 at 14:53
  • 1
    It's really awkward to ask the same question again after 2+ years. But, guys is there any alternative of renderas pdf OR converting the vf page into PDF? Jul 13, 2022 at 4:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .