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
Pooja05Pooja05 

Rendering a page as pdf with landscape layout

Hi,

 

I want to render a page as PDF but the table has too many columns and looks messy in a potrait style layout.

 

How can I change it to landscape layout?

 

 

thanks,

Pooja

shillyershillyer

Hi Pooja,

 

Try this:

 

<apex:page renderas="pdf"> <style> @page { size: landscape; } </style> </apex:page>

 

 

 

Hope that helps,

Sati

Pooja05Pooja05

<apex:page renderAs="pdf">
<style>
    @page
    {
        size:landscape;
    }
</style>
    <apex:outputText value="Hi"/>
</apex:page>

 

I tried it, but it doesnt work.

TehNrdTehNrd
Try putting the style tags in a css file, upload as a static resource then use the apex:stylesheet tag. This seems to work a lot better when use CSS in PDF generation.
tim-at-hastingstim-at-hastings

I'm missing something or there is an issue here. I have placed an @page { size:landscape;} block into a css file and uploaded it as a static resource named landscapePDF. This is what I have in my Visuleforce page...

<apex:page standardController="awhWorkshopSchedule__c" renders="pdf">
<apex:stylesheet value="{!$Resource.landscapePDF}"/> bla bla bla...
 But when the PDF is rendered it is not landscape.ThePDF producer is iText 2.0.8 and the PDF version is 1.4(Acrobat 5.x)
TehNrdTehNrd

Try this:

 

 

<apex:stylesheet value="{!URLFOR($Resource.landscapePDF)}"/>

 

 

tim-at-hastingstim-at-hastings

URLFOR() isn't doing it either. I removed the renderAs attribute from the page tag so I could look at the HTML markup and see if the link tag was even being added and what I found was the link tag was added but the href attribute was missing the .css file extension. So I did this...

<apex:stylesheet value="{!$Resource.landscapePDF}.css"/>
and then this...

 <apex:stylesheet value="{!URLFOR($Resource.landscapePDF)}.css"/

Both approaches added the correct href in the link tag but that still didn't solve the problem after resetting renderAs back to pdf. So I have confirmed that the link tag is being added and that the href is correct when rendering as a normal HTML page but when rendering as PDF it looks like its not picking up the stylesheet at all.

tim-at-hastingstim-at-hastings

Oops... You shouldn't add .css to the href. That has nothing to do with it. I added a class to my stylesheet and set a background-color and then set a div tag class attribute to that class. The pdf is rendered and the div tag shows the background color I set in the stylesheet. So the stylesheet is picked up but still no landscape.

 

Is it an error with my css file...

@page {
size:landscape;
}

.testico {
background-color:#cccccc;
}
Message Edited by tim-at-hastings on 04-10-2009 03:22 PM
Christian ArroyoChristian Arroyo

Hi!! All of the posts are correct but they're only missing <head> tag. I have this code and works fine:

 

<apex:page renderAs="PDF">
  <head>
    <style>

        @page{
            size: landscape;
        }
    </style>
  </head>
  <h1>Testing Landscape</h1>
  Rendering PDF as Landscape

</apex:page>

 

 

Sumit Kumar 339Sumit Kumar 339
You have to use applyBodyTag="false" attribute in <apex:page tag as explained in Visualforce Developer Guide to render the PDF properly. I checked with the below code and I am able to render the PDF in landscape mode.
 
<apex:page standardController="Account" renderAs="pdf" applyBodyTag="false">
    <head>
        <style>
            @page{
                size: A4 landscape;
            }            
            body {
                font-family: 'Arial Unicode MS';
            }
            .companyName {
                font: bold 30px; color: red;
            }  
        </style>
    </head>
<apex:page>

 
shaanafoyel shaanafoyelshaanafoyel shaanafoyel
Whichever trees or plants you have all through your yard, our accomplished professionals can keep them all putting their best self forward. 
Tall timber tree landscaping service (https://talltimbertree.com/residential-landscaping-services/) Get in touch with us today to give your gardens the highest caliber of care around.