0

I am creating word document using vfpage,i am getting a second page as blank.how to remove this blank page.for referenced i attached png image.Thanks in advance.

My Code:

<apex:page applyHtmlTag="true" extensions="QuoteChangeOrderRequest" standardController="Quotes__c"  showChat="false" showHeader="false" sidebar="false"  cache="true" contentType="application/msWord#msword.doc">
    <!---apex:page applyHtmlTag="true" controller="TestMSword"  showChat="false" showHeader="false" sidebar="false"  cache="true" contentType="application/msWord#msword.doc"--->
     <html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='<a target="_blank" href="http://www.w3.org/TR/REC-html40" rel="nofollow">http://www.w3.org/TR/REC-html40</a>'>        <head>
        <style>
            p.MsoHeader, li.MsoHeader, div.MsoHeader{
            margin:0in;
            margin-top:.0001pt;
            mso-pagination:widow-orphan;
            tab-stops:center 3.0in right 6.0in;
            }
            p.MsoFooter, li.MsoFooter, div.MsoFooter{
            margin:0in;
            margin-bottom:.0001pt;
            mso-pagination:widow-orphan;
            tab-stops:center 3.0in right 6.0in;
            }
            @page Section1{
            size:8.5in 11.0in; 
            margin:0.5in 0.5in 0.5in 0.5in;
            mso-header-margin:0.5in;
            mso-header:h1;
            mso-footer:f1; 
            mso-footer-margin:0.5in;
           mso-paper-source:0;

            }
            div.Section1{
            page:Section1;
            page-break-after:none;
            }
            /*Below is the style to prevent the repetition of header and Footer.. */
            table#hrdftrtbl{
            margin:0in 0in 0in 9in;
            } 
           tr.bottom td { border-bottom: thin solid red; }
               tr.spaceUnder > td
{
  padding-bottom: 4em;
}
        </style>
        </head>

        <body>
            <!-- Content -->
            <div class="Section1"><!--Section1 div starts-->
                <!-- Page 1 starts -->
               <table width="100%" id="#hrdftrtbl">

                <!--------Project layout and rep------>
                <tr><th align="left" style="font-weight:bold;font-size:15px">PROJECT INFORMATION</th></tr>
                <tr>
                    <td width="50%" align="left" >
                        <span style="font-weight:bold;">Project</Span> {!ProjName}</td><td></td> </tr>
                       <tr> <td align="left"  >Location{!ProjLocation} </td> <td></td></tr>
                       <tr> <td align="left"  ><span style="font-weight:bold;">Customer</Span>{!CustomerName}</td> <td   align="left"><span style="font-weight:bold;font-size:20px">{!ProductId}</span></td> </tr>
                       <tr> <td align="left"  ><span style="font-weight:bold;">Representative</span>{!RepName}</td> <td align="left"><span style="font-weight:bold;">C/S Job #</span> {!CSJob}</td> </tr>
                       <tr> <td align="left">Location{!RepLocation}</td> <td  align="left" width="50%"><span style="font-weight:bold;"> COR Date:</span> <span style="padding-left:20px"/>{!CORDate}</td> </tr>
                       <tr><td>{!RepCity}</td><td></td></tr>
                       <tr> <td align="left" >Email{!RepEmail}</td><td></td> </tr>
                       <tr class="bottom"> <td align="left">Phone{!RepPhone}</td><td></td> </tr>
                      <!-- <tr class="bottom"><td></td><td></td></tr> -->
          </table>
            <table>
                <!--------head change order req form--->
              <tr><th align="left">{!QuoteName}</th></tr>
                <tr class="spaceUnder">
                    <td align="left" width="40%">
                        The original contract sum</td><td width="30%">$ </td> </tr>
                       <tr class="spaceUnder"> <td align="left" width="40%" >Net change order(s) previously authorized </td> <td width="30%">$ </td></tr>
                       <tr class="bottom"> <td align="left" width="40%" >Contract sum prior to this change order </td> <td align="left" width="30%">$</td> </tr>
                       <tr class="spaceUnder"><td align="left" width="45%" style="font-weight: bold;">The contract sum will INCREASE by change order amount of </td><td align="left" width="30%">$</td></tr>
                       <tr ><td align="right" width="40%" style="font-weight: bold;">The New Contract sum</td><td  width="30%">$</td></tr>
            </table>  <br/>

            <!-----scope of---->
             <table>
                <!--------head change order req form--->
                <tr class="bottom"><span style="font-weight:bold;">Scope of change order request:</Span><td></td></tr>
             <tr><br/><br/><br/><br/> <BR/><BR/><td align="left"  ><span style="font-weight:bold;"></Span>{!Model}</td> </tr>
             <tr> <td align="left"  ><span style="font-weight:bold;"></Span>{!Finish}</td> </tr>
             <tr> <td align="left"  ><span style="font-weight:bold;"></Span>{!Screen}</td> </tr>

       <tr class="bottom"><td align="left"><span style="font-weight:bold;">C/S cannot proceed with revised shop drawings or fabrication until the signed change order is received.</span> </td><td></td><td align="left"></td></tr><br/><br/>
            </table>  

             <table> 
                <!--------head change order req form--->
                <tr class="spaceUnder"><td align="left" >Proposal issued by: <span style="padding-left:20px"/>{!$User.firstName} <span style="padding-left:20px"/>{!$User.lastname}</td><td align="center"  width="20%"></td><td width="30%" align="right">
                        Post Order Sales Manager</td></tr>
            <tr class="spaceUnder"><br/><td align="left">Change order request accepted by:</td><td align="center" width="35%"></td><td align="right" width="30%"></td></tr>
            <tr class="spaceUnder"><td align="left">{!CustomerSig}</td> <td  align="center" width="35%">____________________</td><td align="right" width="30%">____________________</td></tr>
                        <tr><td ></td><td align="center" width="20%">Name</td><td align="center" width="20%">Date</td></tr> 

            </table> 

          </div>
          <br clear="all" style="page-break-before:avoid" />
          <!--Section1 div ends
               **<br clear="all" style="page-break-before:avoid" />**



                <!--Header and Footer Starts-->

                <table id='hrdftrtbl'  cellspacing='0' cellpadding='0'>
                    <tr >
                        <td>
                            <!--Header-->
                           <div style='mso-element:header' id="h1" >
                                <p class="MsoHeader">
                                    <table  width="100%">
                                        <tr>
                                            <td width="30%">
                      <apex:image url="https://c-sgroup--maya--c.cs3.content.force.com/servlet/servlet.ImageServer?id=015Q0000000TieJ&oid=00DQ000000GKKav"  width="350" height="90" />  

                                            </td>
                                            <td align="center" width="0%">
                                              <!--  Center<br/> Header -->
                                            </td> </tr>
                                         <tr class="bottom">   <td align="right" width="40%">
                                                <apex:outputtext style="font-size: 15px;text-align:right" value="49 Meeker Avenue Cranford, NJ 07016"></apex:outputtext> <br/>
                                                <apex:outputText style="font-size: 15px;text-align:right" value="TEL: 908-272-5200"></apex:outputText>
                                            </td>
                                        </tr >
                                       <!-- <tr width="100%"><hr width="100%" style="color:#FF0000"></hr></tr> --> 

                                </table>
                            </p>
                        </div>
                </td>

                <td>
                    <!--Footer-->
                    <div style='mso-element:footer' >
                        <p class="MsoFooter">
                            <table width="100%" border="1" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="30%">

                                    </td>
                                    <td align="center" width="40%">

                                    </td>
                                    <td align="right" width="30%">
                                        <span style='mso-field-code: PAGE '></span> of <span style='mso-field-code: NUMPAGES '></span>
                                    </td>
                               </tr>

                        </table>
                    </p>
                </div>
        </td>
    </tr>
</table>

</body>
</html>
</apex:page>

o/p second blank page is coming with header

1 Answer 1

4

In your Apex code, do this

<apex:variable var="cnt" value="{!0}" />    
<apex:repeat value="{!cases}" var="cse"> 
      <!-- apex:OutputText value="{!cnt}"/ -->
     <div style="{!if(cnt < 1, 'page-break-before:avoid;','page-break-before:always;')}">
     <apex:variable var="cnt" value="{!cnt+1}"/> .... .... </div> 
 </apex:repeat>

I can certify this works for PDF (I answered that thread) and I think it should work for Word doc as well.

1
  • Hi Thank you for answering, using above suggestions that code pages are increasing perfect but not removing.can you give any other possible ways
    – pree_sfdc
    Commented Jun 22, 2016 at 17:57

You must log in to answer this question.

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