1

I am preparing Msword(Proposal) document in salesforce visualforce page.There is a small box in a header and footer level and special character in the content. I want to remove the small box and replace the enter image description herespecial character with actual characters. Kindly help me.

See the below code and attached error image

 <apex:page sidebar="false" contentType="application/msword#{!filename}.doc" cache="true" controller="GenerateDoccumentController" lightningStylesheets="true">
    
    <html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='https://www.w3.org/TR/2018/SPSD-html401-20180327/'> 
    
        <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;
                }
                /*Below is the style to prevent the repetition of header and Footer.. Cheers!!!*/
                table#hrdftrtbl{
                    margin:0in 0in 0in 9in;
                }       
            </style>
        </head>

        <body>
            <!-- Content -->
            <div class="Section1"><!--Section1 div starts-->
                <center>
              <apex:outputPanel rendered="{!proposalHead}">
              <p><b><u>Proposal</u></b></p>
              </apex:outputPanel>
              
              <apex:outputPanel rendered="{!tradeHead}">
              <p><b><u>Trade Recap</u></b></p>
              </apex:outputPanel>
              
              </center>
              
              <apex:outputPanel rendered="{!proposalText}">
              <p>Attn:    {!gdw.contactRoleName} </p>
              <p> Ref.:   {!gdw.year} Proposal for up to {!gdw.totalOppQty} metric tons of {!gdw.prodGroup} Zinc. </p>
              <p> Please find below our proposal for the supply of {!gdw.prodGroup} Zinc during Calendar year {!gdw.year} </p>
              </apex:outputPanel>
              
              <apex:outputPanel rendered="{!tradeText}">
             <!-- <p>Pursuant to the Master Sale and Purchase Agreement (the "Master Agreement") reference number {!gdw.contractRef}, between {!gdw.seller} and {!gdw.buyer}, the parties agree upon the following sale and purchase on {!gdw.closeDt}</p>
               <p>To the extent not inconsistent with this Trade Recap but not defined herein shall have the meanings given them in the Master Agreement.</p>-->
                  {!gdw.tradeInitialPara}
               </apex:outputPanel>
               
               <table style="width:100%" border="1">
              
              <tr>
                <td>1</td>
                <td>Contract Ref:</td>
                <td>{!gdw.contractRef}</td>
              </tr>
              <tr>
                <td>2</td>
                <td>Seller:</td>
                <td>{!gdw.seller}</td>
              </tr>
              <tr>
                <td>3</td>
                <td>Buyer:</td>
                <td>{!gdw.buyer}</td>
              </tr>
              <tr>
                <td>4</td>
                <td>Metal:</td>
                <td><apex:outputtext value="{!gdw.metal}" escape="false"/></td>
              </tr>
              <tr>
                <td>5</td>
                <td>Quantity:</td>
                <td>{!gdw.quantity}</td>
              </tr>
              <tr>
                <td>6</td>
                <td>Quality and Brand:</td>
                <td><apex:outputtext value="{!gdw.quantityAndBrand}" escape="false"/></td>
              </tr>
              
              <tr>
                <td>7</td>
                <td>Delivery Period:</td>
                <td>{!gdw.deliveryPeriod}</td>
              </tr>
              <tr>
                <td>8</td>
                <td>Delivery:</td>
                <td>{!gdw.deliveryLocation}</td>
              </tr>
              <tr>
                <td>9</td>
                <td>Origin:</td>
                <td>{!gdw.origin}</td>
              </tr>
              <tr>
                <td>10</td>
                <td>Price:</td>
                  <td>  {!a} <br/> <apex:outputtext value="{!gdw.price}" escape="false"/> <br/> <apex:outputtext value="{!b}" escape="false"/> <br/>{!c} </td>
                
              </tr>
              
              
              <tr>
                <td>11</td>
                <td>Quotational Period:</td>
                <td>{!gdw.quotationalPeriod}</td>
              </tr>
              <tr>
                <td>12</td>
                <td>Payment:</td>
                <td>{!gdw.payment}</td>
              </tr>
              <tr>
                <td>13</td>
                <td>Weights:</td>
                <td>{!gdw.weights}</td>
              </tr>
              <tr>
                <td>14</td>
                <td>Law/Jurisdiction:</td>
                <td>{!gdw.law_Jurisdiction}</td>
              </tr>
              <tr>
                <td>15</td>
                <td>General Terms and Condition:</td>
                <td>{!gdw.terms_Condition}</td>
              </tr>
               <apex:outputPanel rendered="{!framerow}">
              <tr>
                <td>{!framelinenumber}</td>
                <td>Frame details:</td>
                <td>{!gdw.FrameDet}</td>
              </tr>
              </apex:outputPanel>
              <apex:outputPanel rendered="{!tableRow}">
              <tr>
                <td>{!validitylinenumber}</td>
                <td>Validity:</td>
                <td>{!gdw.closeDt}</td>
              </tr>
              </apex:outputPanel>
              
            </table>
              
                <!--Header and Footer Starts-->
                <table id='hrdftrtbl' ><!--border='1' cellspacing='0' cellpadding='0'-->
                    <tr>
                        <td>
                            <!--Header-->
                            <div style='mso-element:header' id="h1" >
                               <p class="MsoHeader">
                                    <center>
                                      <apex:image url="{!$Label.URL}id={!$Label.DocumentId}&oid={!$Label.OrganizationId}&lastMod={!$Label.LastModified}" width="150" height="75"/><br/>
                                      
                                       <b>{!gdw.seller}</b>
                                      </center>
                                      <br/>
                                    
                                </p>
                             
                            </div>
                            <!-- <div style='mso-element:header' id="h1">
                                 <p class="MyHead">Header Text</p></div>-->
                           
                        </td>

                        <td>
                            <!--Footer-->
                            <div style='mso-element:footer' id="f1">
                                <p class="MsoFooter">
                                    <center>
                                        <b>{!gdw.seller}</b> <br/>
                                        {!gdw.Address1} <br/>
                                        {!gdw.Address2} <br/><br/>
                                    </center>
                                    
                                </p>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </body>    
    </html>  
</apex:page>

enter image description here

0

The issue is a stray character or characters. I don't see any special characters (Unicode or control) in your markup that your font is struggling with, so I'm leaning towards malformed markup. A few things to try.

  1. Remove the Lightning Style Sheets from your apex:page (lightningStylesheets="false"). At best they do nothing, at worst they interfere with formatting.
  2. Include showHeader="false" in apex:page. I doubt it's an issue, but it doesn't hurt to be explicit.
  3. Remove the HTML comments from your CSS (<!-- *************-->). CSS comments are in the format /* comment */.

Additionally, I know it can be counter-intuitive to not use Visualforce tags in a Visualforce page, but the output they generate may be an issue. If you can, I would consider using only valid HTML tags in your markup to eliminate potential issues. If you keep any of the VF tags, it would be apex:outputPanel because those either generate markup or they don't, but I would use layout="none" on them so they aren't generating extra <span> tags around your markup (it should be fine without them).

You can take your document and open it up in an IDE to get a glimpse of the underlying XML, but with documents such as these the issue would be difficult to find.

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.