Find your content:

Search form

You are here

Adding a border to a visualforce page rendered as a PDF

 
Share

I am trying to make a visualforce page with a border that renders as a PDF. Currently, there are 2 sets of tables within the visualforce page, both of which can have variable sizes depending on the results of a search. I would like to have a border on each page of the pdf, regardless of how many pages it goes to.

Here is my code:

<apex:page controller="SearchController" sidebar="false" renderAs="PDF" showHeader="false" >    
    <apex:form style="border:10px double #990033;">
<apex:pageMessages id="errors" />

<apex:pageBlock mode="edit" id="results"> 
   <div style="display: block;min-height: 9.25in;padding: 15px;">
      <table width="100%" border="0">
          <tr>  

            <td valign="top">

                <apex:image url="{!DocumentLogoUrl}" width="256" height="175" style="display: block;margin-left: auto;margin-right: auto; padding:25px;"/>

                <p>Search Results</p>

                <p><u>Town:</u><b> {!curTown}</b>

        <apex:pageBlockTable value="{!contacts}" var="contact">

             <apex:column width="25%" >
                <apex:facet name="header">
                    <apex:outputLabel value="Contact">
                    </apex:outputLabel>
                </apex:facet>
                <apex:outputLabel value="{!contact.firstname}"/>
             </apex:column>

             <apex:column width="25%">
                <apex:facet name="header">
                    <apex:outputLabel value="Owner">                     
                    </apex:outputLabel>
                </apex:facet>
                <apex:outputField value="{!contact.owner.name}"/>
            </apex:column>
          </apex:pageBlockTable>
        </td>
        </tr>
     </table>   
 </div>
</apex:pageBlock>

</apex:form>
</apex:page>

In this example, the towns listed can be of any length and the table of contacts and owners can also be of any length. I would like the border to go around each page. Currently,it gets cut off at the first page and continues onto the last page and ends there. Any suggestions?


Attribution to: Katie Swol

Possible Suggestion/Solution #1

Try to add a border to the @page css rule (the page area includes the boxes laid out on that page). Because of the page area the border will be drawn on each generated page:

<apex:page renderAs="pdf"
           applyHtmlTag="false" 
           showHeader="false" 
           cache="true"
           readOnly="true">

    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <style type="text/css">
    @page {
        size:A4 portrait;
        border: 2px solid black;    
    }
    </style>
    </head>

    Your content here...

</apex:page>

Image


Attribution to: Sergej Utko
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32196

My Block Status

My Block Content