Print this page

How to alter the page margins of the PDF page rendered using renderAs="pdf" option

Knowledge Article Number 000188118
Description

- VisualForce page has the “renderPDF” option. However, if we try to enhance it with page style, it doesn’t work in API version 27.0 and 28.0. 

           <head>

                    <style>

                             @page {

                                    margin-left: 10cm;

                                    margin-right: 10cm;

                              }

                     </style>

             </head>

 The margins do not take into effect in the above code. Same code works in API version 26.0.

Resolution

To properly enhance page styles (margins etc)  add the following tags:

1. Set "applyHtmlTag" attribute of page to "false"

2. Set "applyBodyTag" attribute of page to "false".

<apex:page showHeader="false" sidebar="false" standardStylesheets="false" renderAs="pdf" applyHtmlTag="false" applyBodyTag="false" >

             <head>

                    <style>

                             @page {

                                    margin-left: 10cm;

                                    margin-right: 10cm;

                              }

                     </style>

             </head>

The applyHtmlTag attribute is available on the <apex:page> tag for Visualforce pages set to API version 27.0 or higher.

The applyBodyTag attribute is available on the <apex:page> tag for Visualforce pages set to API version 28.0 or higher





promote demote