Lightning Component With Custom PDF Preview


Lightning Component With Custom PDF Preview

Custom PDF with Header,Content and Footer

PDF Visualforce Page (renderAs="pdf")



<apex:page applybodytag="false" applyhtmltag="false" cache="false" renderas="pdf" showheader="false" sidebar="false" standardcontroller="Account" standardstylesheets="false">

    <head>
        <style media="print" type="text/css">
            body {
                font-family: sans-serif !important;
                font-size: 12px !important;
            }

            @page {
                size: A4;
                margin-bottom: 35mm;
                padding-top: 201px;
                margin-right: 0;

                @top-center {
                    content: element(header);
                }

                @bottom-right {
                    content: element(footer);
                }

            }

            div.header {
                display: block;
                text-align: center;
                position: running(header);
            }

            div.content {
                display: block;
                margin: 40px;

            }

            div.footer {
                display: block;
                position: running(footer);
            }
        </style>
    </head>
    <div class="header">
        <!-- Set Header Image form Static Resource -->
        <!-- <img src="{!$Resource.Header}" title="header" width="800px" /> -->
    </div>
    <div class="footer">
        <!-- Set Footer Image form Static Resource -->
        <!-- <img src="{!$Resource.Footer}" title="footer" width="800px" /> -->
    </div>
    <div class="content">
        <table border="0" cellpadding="5" cellspacing="0" style="margin: 40px; width: 80%px;">
            <tbody>
                <tr>
                    <td>
                        <div style="font-size: 51px;">
                            Cover Page
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
        <div style="page-break-after: always;">
            <apex:repeat value="{!Account.contacts}" var="con">
            </apex:repeat><br />
            <table border="1" cellpadding="5" cellspacing="0" style="margin: 40px; width: 80%px;">
                <tbody>
                    <tr>
                        <td style="background-color: #cccccc;">Name</td>
                        <td style="background-color: #cccccc;">Email</td>
                        <td style="background-color: #cccccc;">Phone</td>
                        <td style="background-color: #cccccc;">Birthdate</td>
                    </tr>
                    <tr>
                        <td>{!con.Name}</td>
                        <td>{!con.Email}</td>
                        <td>{!con.Phone}</td>
                        <td>{!con.Birthdate}</td>
                    </tr>
                </tbody>
            </table>
            <div style="page-break-after: always;">
                <table border="0" cellpadding="5" cellspacing="0" style="margin: 0 auto; width: 100%px;">
                    <tbody>
                        <tr>
                            <td>
                                <div style="font-size: 51px;">
                                    Last Page
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</apex:page>



Lightning Component for PDF Preview


CustomPDFPreview.cmp (Component)


<aura:component access="global" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:lightningQuickAction">
    <iframe frameborder="0" height="500px;" src="{!'/apex/CustomPDFWithHeaderAndFooter?id='+  v.recordId}" width="100%"/>
</aura:component>


PDF Preview Lightning Component Output UI
Note: After save whole code you will drag and drop code into Lightning Record Detail Page Or Quick Action

Happy Sharing...

Everyone has their own favourites, so please feel free to share yours in the comments below!

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Your post was helpful in many ways. It was agreeable with our fellow developers.
    Salesforce Lightning Services

    ReplyDelete

Post a Comment

Popular posts from this blog

Salesforce LWC : Compact Layout on Hover

Salesforce LWC With Third Party JS : D3

Communications between Lightning Components : Salesforce