function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
YRYR 

Render PDF as landscape issue ??

Hi

 

I tried to make the visualforce page renderas PDF in landscape with following styles

 

<style >
    @page {
        size:landscape;
   }
 </style>
 

 

But it is not working now. Is anybody face the same issue? or have any idea to render the PDF as landscape??

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Following code will work...

 

<head>

<style>

@page {

size:landscape;

}

</style> 

</head> 

Message Edited by prageeth on 09-29-2009 12:31 AM

All Answers

etoeto

The pdf renderer has some limitations, maybe this is one of them.

 

The usage of a specific size in the @page-elements works for me, e.g.:

 

 

@page { size: 29.7cm 21.0cm ; margin-top: 1.0cm; margin-left: 1.0cm; margin-right: 1.0cm; margin-bottom: 1.0cm; }

 

(european standard paper, 1cm border on each side)

 

hth

Ingo

 

prageethprageeth

Following code will work...

 

<head>

<style>

@page {

size:landscape;

}

</style> 

</head> 

Message Edited by prageeth on 09-29-2009 12:31 AM
This was selected as the best answer
AdamXLAdamXL

Neither specifying the size as landscape or as 29.7cm, 21.0cm seams to get the rendering of PDF to actually be landscape mode. Anyone recently able to do this?

shizzle94shizzle94
Just had the same problem, I see this was a recent post. The chosen answer here works, however, not in API version 27, you need to go back to API version 26 on your vf page.
StaceyWStaceyW

I had this problem for a while, and then I figured out that the tag <html> which I was usind was creating the problem make sure that there aren't any extra tags. 

 

<apex:page renderAs="PDF">
  <head>
   <style>
     @page{
        size: A4 landscape;
                  }
    </style>
   </head>
<h1>Testing Landscape</h1>
Rendering PDF as Landscape
</apex:page>

csreddy7799csreddy7799

This is not working in Salesforce.com API version 28.0

 

 

kevingwynnkevingwynn

Just to verify, the following does work for me.

 

<apex:page renderAs="pdf">
	<head>
		<style>
			@page { size:landscape; }
		</style>
	</head>
	<h1>Test</h1>
</apex:page>

 However it works in API version 26 and 27 only. Renders as portrait in API version 28.

 

Also, the "<head>" tag is critical - it does not work without it.

AlejandroRaigonAlejandroRaigon
In version 28.0 and above, for the styles to be honoured by the PDF engine the markup has to be valid. Using version 28.0 or above the below VF page renders in landscape.

<apex:page renderAs="PDF" applyBodyTag="false" applyHtmlTag="false" showHeader="false">
<html>
<head>
<style>
@page{
size: A4 landscape;
}
</style>
</head>
<body>
<h1>Testing Landscape</h1>
Rendering PDF as Landscape
</body>
</html>
</apex:page>
CRMDCRMD
The HTML tags are crucial.  Thank you!
Rich PRich P
This is a confusing thread because it sounds like different tags work with different API versions. Hopefully this will help clarify. I created a new VisualForce page by copying code from a page that was rendering properly in landscape (API v27), I found that the new page (API v29) no longer rendered in landscape though the code was identical. Here is the relevant styling:

<apex:page id="apex_page" standardcontroller="Day_of_Caring_Project__c" extensions="DoCProjectReportController" tabStyle="Account" renderAs="pdf" showheader="false" >
    <head>
        <style type="text/css">
              @page
              {    
                /* Landscape orientation */
                  size:landscape;
                  margin:0.25in;
            }                            
        </style>
    </head>

That styling works (the page renders in landscape) when the page-meta.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>27.0</apiVersion>
    <availableInTouch>false</availableInTouch>
    <confirmationTokenRequired>false</confirmationTokenRequired>
    <label>DoCMatchByAgencyReportTZ</label>
    <packageVersions>
        <majorNumber>2</majorNumber>
        <minorNumber>0</minorNumber>
        <namespace>npe01</namespace>
    </packageVersions>
</ApexPage>

The page renders as incorrectly portrait when the page-mega.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>29.0</apiVersion>
    <availableInTouch>false</availableInTouch>
    <confirmationTokenRequired>false</confirmationTokenRequired>
    <label>DoCMatchByAgencyReportTZ</label>
    <packageVersions>
        <majorNumber>3</majorNumber>
        <minorNumber>0</minorNumber>
        <namespace>npe01</namespace>
    </packageVersions>
</ApexPage>

So it looks like the API Version is a very important factor when troubleshooting this problem.
Eric Clay!Eric Clay!
AlejandroRaigon's answer is the correct answer for the current API version. Make sure to match the applyBodyTag="false" applyHtmlTag="false" settings. If it doesn't work, create a blank page and copy/paste the code in and troubleshoot from there.
ChellappaChellappa
Eric is right. 

AlejandroRaigon's answer works well. My page is currently in the latest 46.0 version and it works.
Thanks,
Chellappa