Is there any way to create PDF attachment for VF Page with Lightning Out component in it:


<apex:page showHeader="false" controller="PageController" standardStylesheets="false" lightningStylesheets="true"

<apex:includeLightning />


          Is main text

            $Lightning.use("c:LightningApp", function() {
                    function(cmp) {
                        // do some stuff



<aura:component description="HeaderComponent">
   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

     <div aura:id="main" id="mainDiv">

          <p> Is Embedded Text </p>



Attachment pdfattachment = new Attachment();

pdfattachment.Name = system.now() + '.pdf'; //put your attachment name
PageReference pdfPage = new PageReference( '/apex/myContent');

pdfattachment.Body = pdfPage.getContentAsPDF();
pdfattachment.ContentType = 'application/pdf';
pdfattachment.parentId = 'XXXXXX000AM5QL'; //(Put your Parent Object ID here)

insert pdfattachment;

When I open VF page with embedded component" - I can see both "Is main text" and "Is Embedded Text" But when I open created attachment - only "Is main text" is populated. Is there any way how we can store the content from VF Page and its embedded component as PDF in the system?

  • renderAsPDF does not run JS on visualforce, so it is not possible so far
    – kurunve
    May 12, 2020 at 15:32
  • @kurunve. I am trying to use pdfPage.getContentAsPDF(), not "renderAsPDF" May 12, 2020 at 15:39
  • 1
    It uses same engine behind -- server-side renderer for renderAsPDF and getContentAsPDF
    – kurunve
    May 12, 2020 at 15:41
  • @kurunve any workaround? May 12, 2020 at 15:48
  • 1
    @ValentinePotapov Again, that question shows that we can't render components as PDF.
    – sfdcfox
    May 12, 2020 at 17:53


Browse other questions tagged .