1

I need to modify the below page to generate a PDF and modify the PDF exporting settings to export a table of only 10 records on each page.

<apex:page standardController="Contact" recordSetvar="Cont">
<head>
    <style>
        .head { font-size:1.3em; }
    </style>
</head>
<apex:slds />
<body>
    <div class="slds-scope">
        <apex:form>
            <apex:sectionHeader title="Financial Force Contacts" subtitle="Financial Home" help="https://help.salesforce.com/articleView?err=1&id=contacts_overview.htm&siteLang=en_US&type=0" />
            <apex:panelGrid columns="6">
                <apex:outputLabel value="View:" />
                <apex:selectList value="{!filterId}" size="1" id="sel">
                    <apex:actionSupport event="onchange" action="{!list}" />
                    <apex:selectOptions value="{!listviewoptions}" />
                </apex:selectList>
                <apex:commandButton value="GO!" action="{!list}" />
                <apex:outputLink value="/ui/list/FilterEditPage?id=00B6F00000Al7Mj&retURL=%2F003&cancelURL=%2F003%2Fo">
                    <apex:outputtext value="Edit"/>
                </apex:outputLink>|
                <apex:outputLink value="/ui/list/FilterEditPage?ui/list/FilterEditPage?ftype=c&retURL=%2F003&cancelURL=%2F003%2Fo">
                    <apex:outputtext value="Create New View"/>
                </apex:outputLink>
            </apex:panelGrid>

            <apex:pageBlock>
                <apex:panelGrid columns="2" width="50%">
                    <h1 class="head">Recent Contacts</h1>
                    <apex:commandButton value="New" action="/001/e" />
                </apex:panelGrid>
                <apex:pageBlockTable value="{!cont}" var="item"  id="list">
                    <apex:column headerValue="Name">
                        <apex:outputLink value="/{!item.id}">
                            <apex:outputText >{!item.name}</apex:outputText>
                        </apex:outputLink>
                    </apex:column>
                    <apex:column headerValue="Account Name">
                        <apex:outputLink value="/{!item.accountid}">
                            <apex:outputtext value="{!item.Account.name}"/>
                        </apex:outputlink>
                    </apex:column>

                    <apex:column headerValue="Phone">
                        <apex:outputtext value="{!item.phone}"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:form>
    </div>
</body>

I used renderAs=pdf to generate the page in pdf which displays 20 records in a table.

To apply page break after 10 records, I tried with apex:repeat, div style="page-break-after:always; and apex:variable but it does not seem to work.

Please help me on this.

1

I tried the following code and it worked. For the benefit of readers, I am posting the below code:

    <apex:page sidebar="false" showHeader="false" standardController="Contact" recordSetvar="Cont" renderAs="pdf" applyBodyTag="false" applyHtmlTag="false">

<head>
    <style type="text/css" media="print">
        .head {
            font-size: 1.3em;
        }

        @page {
            size: A4 landscape;

            @top-center {

                content: element(header);

            }

            size: 210mm 297mm;
            margin: 15mm;
            margin-right:0mm;

            margin-top: 4.215cm;
            margin-bottom: 2.80cm;
            margin-left: 1.27cm;
            margin-right:1cm;

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

        }

        div.header {
            padding: 10px;
            position: running(header);
            height: 80px;
            margin-bottom: 15px;
        }

        div.footer {

            display: block;

            padding: 5px;

            position: running(footer);
            clear: both;
            margin-top: 15px;

        }

        .pagenumber:before {
            content: counter(page);
        }

        .pagecount:before {
            content: counter(pages);
        }


        .labelcls {
            margin-left: 100px;
            font-size: 15px;

        }
    </style>
</head>
<apex:form >
    <div class="header" width="100%">
        <div>
            <apex:outputLabel styleclass="labelcls">Financial Force</apex:outputLabel>
            <apex:outputLabel style="font-size:15px; margin-left:50px; margin-right:70px;" value="Financial Force">
            </apex:outputLabel>
            <apex:outputLabel style="font-size:15px; margin-left:100px; margin-right:30px;" value="Financial Force">
                &nbsp;&nbsp;
            </apex:outputLabel>
        </div>
    </div>


    <div class="footer" style="font-size:10px;">
        <p align="center">Page <span class="pagenumber" /> of <span class="pagecount" /></p>
    </div>

    <div>
        <apex:sectionHeader title="Financial Force Contacts" subtitle="Financial Home" help="https://help.salesforce.com/articleView?err=1&id=contacts_overview.htm&siteLang=en_US&type=0" />
        <apex:panelGrid columns="6">
            <apex:outputLabel value="View:" />
            <apex:selectList value="{!filterId}" size="1" id="sel">
                <apex:actionSupport event="onchange" action="{!list}" />
                <apex:selectOptions value="{!listviewoptions}" />
            </apex:selectList>
            <apex:commandButton value="GO!" action="{!list}" />
            <apex:outputLink value="/ui/list/FilterEditPage?id=00B6F00000Al7Mj&retURL=%2F003&cancelURL=%2F003%2Fo">
                <apex:outputtext value="Edit" />
            </apex:outputLink>|
            <apex:outputLink value="/ui/list/FilterEditPage?ui/list/FilterEditPage?ftype=c&retURL=%2F003&cancelURL=%2F003%2Fo">
                <apex:outputtext value="Create New View" />
            </apex:outputLink>
        </apex:panelGrid>

        <apex:pageBlock >
            <apex:variable value="{!1}" var="num" />
            <apex:panelGrid columns="2" width="50%">
                <h1 class="head">Recent Contacts</h1>
                <apex:commandButton value="New" action="/001/e" />
            </apex:panelGrid>

            <apex:repeat value="{!Cont}" var="item" id="list">

                <!-- -------------FOR PAGINATION START--------------- -->
                <apex:outputpanel rendered="{!num == 1  || num == 11 || num == 31 || num == 51 || num == 71 || num == 91 || num == 111 || num == 131}">

                    <table border="1" width="100%" rules="cols">
                        <tr>
                            <td align="left" width="40%">
                                <apex:outputLabel style="font-weight:bold; ">Name</apex:outputLabel>
                            </td>
                            <td align="center" width="25%">
                                <apex:outputLabel style="font-weight:bold; ">Account Name</apex:outputLabel>
                            </td>
                            <td align="center" width="25%">
                                <apex:outputLabel style="font-weight:bold;  ">Phone</apex:outputLabel>
                            </td>
                        </tr>
                    </table>
                </apex:outputpanel>


                <table width="100%" border="1" rules="cols">

                    <tr>
                        <!--<td align="left" width="10%">{!num}</td>-->
                        <td align="center" width="40%">{!item.name}</td>
                        <td align="center" width="25%">{!item.Account.name}</td>
                        <td align="center" width="25%">{!item.phone}</td>
                    </tr>

                </table>

                <apex:outputpanel rendered="{!num == 10 || num ==30  || num == 50 || num == 70 || num == 90 || num == 110 || num == 130 || num == 150}">
                    <!-- ----PAGENATION END -->

                    <div style="page-break-after: always;">&nbsp; </div>

                </apex:outputpanel>
                <apex:variable value="{!num+1}" var="num" />


            </apex:repeat>

        </apex:pageBlock>
    </div>
</apex:form>
  </apex:page>

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.