1

I am not able to remove the blank page from end of the word document. I tried the following ways but i couldn't. Can any one help me on this..

First way :

<div style="page-break-before:always;"/>
        <apex:outputPanel rendered="{!historyList.SIZE > 0}">
            <apex:variable var="cnt" value="{!0}" /> 
            <div Style="font-size:20px; color: #000080"> <b>Version History</b> </div>
            <table style="width:100%">
                <thead>
                    <tr>
                        <th style="width:30%;text-align:left;font-size:15px">
                            Version #
                        </th>
                        <th style="width:30%;text-align:left;font-size:15px">
                            Created Date
                        </th>
                        <th style="width:30%;text-align:left;font-size:15px">
                            Reason For Change
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <apex:repeat var="history" value="{!historyList}">
                        <tr>
                            <td style="width:30%">
                                {!history.verNo}
                            </td>
                            <td style="width:30%">
                                {!history.createdDate}
                            </td>
                            <td style="width:30%">
                                {!history.reasonForChange}
                            </td>
                        </tr>
                    </apex:repeat>
                </tbody>
            </table>
        </apex:outputPanel>

Second Way:

<apex:outputPanel rendered="{!historyList.SIZE > 0}">
            <apex:variable var="cnt" value="{!0}" /> 
            <div Style="font-size:20px; color: #000080"> <b>Version History</b> </div>
            <table style="width:100%">
                <thead>
                    <tr>
                        <th style="width:30%;text-align:left;font-size:15px">
                            Version #
                        </th>
                        <th style="width:30%;text-align:left;font-size:15px">
                            Created Date
                        </th>
                        <th style="width:30%;text-align:left;font-size:15px">
                            Reason For Change
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <apex:repeat var="history" value="{!historyList}">
                        <div style="{!if(cnt < 1, 'page-break-before:avoid;','page-break-before:always;')}">
                        <apex:variable var="cnt" value="{!cnt+1}"/>
                        <tr>
                            <td style="width:30%">
                                {!history.verNo}
                            </td>
                            <td style="width:30%">
                                {!history.createdDate}
                            </td>
                            <td style="width:30%">
                                {!history.reasonForChange}
                            </td>
                        </tr>
                        </div>
                    </apex:repeat>
                </tbody>
            </table>
        </apex:outputPanel>
  • Do you have header or footer in place? Try disabling them if you have it and if it's not necessary. – SE_User Jul 31 '17 at 12:45
1

Printing Word documents would be similar to printing PDFs in that you'll first want to add contentType="application/msword" to the <Apex:page> line in your code. Then, you'll want to use CSS that includes @media tags for print and for screen. I recommend you try something along the lines of the following:

@media print
{
   size: 8.5in 11in;/* width height */ 
   table { page-break-inside:auto }
   tr { page-break-inside:avoid; page-break-after:auto;}
   thead { display:table-header-group }
}

See this W3C reference for more on the @media tag and paged media.

<#div style="page-break-inside:avoid;">
The stuff inside this div will move to a fresh page if it's too long to fit on the remainder of the current page.
<#/div>

@page { 
  size: 8.5in 11in;/* width height */ 
} 

Add a new attribute to the page tag: "ContentType":

  • For Word: contentType="application/msword"
| improve this answer | |

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.