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
Semira@gmail.comSemira@gmail.com 

renderas pdf with landscape page is not working

Hi all, 

 

I'm trying to create a pdf with VF page and open it as landscape. I'm NOT rendering it on VF page but in apex method otherwise, my VF page does not convert to pdf. Here's my VF page code: 

 

<apex:page standardController="Expenses__c" extensions="PDFGenerator" renderAs="pdf">

<apex:form >

<apex:pageBlock title="Expense Report">

<apex:repeat var="p" value="{!LI}">

<apex:pageblockSection>
<apex:outputText value="{!p.Name}"/>
<apex:outputText value="{!p.Date_Submitted__c}"/>
</apex:pageblockSection>



<table border='1' style="border-collapse: collapse;">
<apex:repeat var="m" value="{!p.Expense_Line_Items__r}">

<tr > <td> <apex:outputText value="{!m.Name}"/> </td>
<td> <apex:outputText value="{!m.Amount__c}"/> </td>
<td> <apex:outputText value="{!m.Date_of_Expense__c}"/></td>
<td> <apex:outputText value="{!m.Payee__c}"/> </td>
<td> <apex:outputText value="{!m.Contact__c}"/> </td>
<td> <apex:outputText value="{!m.Code__c}"/> </td>
<td> <apex:outputText value="{!m.Office__c}"/> </td>
<td> <apex:outputText value="{!m.Job_Number__c}"/> </td>
</tr>
</apex:repeat>

</Table>



</apex:repeat>


</apex:pageBlock>
</apex:form>

</apex:page>

 

 

Here's is the code from Apex method which makes the vforce to pdf. Is there anyway I can make the report to landscape?

 

body = pdf.getContentaspdf();

Best Answer chosen by Admin (Salesforce Developers) 
QingsongQingsong

you will need add style resource, in your case, add ExpensePDF.CSS with below cose

 

@page{
		size:landscape;
		margin-left: 0.8cm; 
		margin-right: 0.8cm;
		margin-top: 0.8cm; 
		margin-bottom: 0.8cm;
		@bottom-left{
			font-family:Arial, Helvetica, sans-serif;
			font-size: 12pt;
			content: "Company"; 
		}
	
		@bottom-center{
			font-family:Arial, Helvetica, sans-serif;
			font-size: 8pt;
			content: counter(page) " of " counter(pages); 
		}
		@bottom-right{
			font-family:Arial, Helvetica, sans-serif;
			font-size: 8pt;
			content: "Confidential"; 	
		}

		
	}

save above code as .css file, and then upload into your static resource name as "ExpensePDF", and then add the style in your page

 

<apex:page standardController="Expenses__c" extensions="PDFGenerator" renderAs="pdf">
<apex:stylesheet value="{!$Resource.ExpensePDF}"/> 

 

All Answers

QingsongQingsong

you will need add style resource, in your case, add ExpensePDF.CSS with below cose

 

@page{
		size:landscape;
		margin-left: 0.8cm; 
		margin-right: 0.8cm;
		margin-top: 0.8cm; 
		margin-bottom: 0.8cm;
		@bottom-left{
			font-family:Arial, Helvetica, sans-serif;
			font-size: 12pt;
			content: "Company"; 
		}
	
		@bottom-center{
			font-family:Arial, Helvetica, sans-serif;
			font-size: 8pt;
			content: counter(page) " of " counter(pages); 
		}
		@bottom-right{
			font-family:Arial, Helvetica, sans-serif;
			font-size: 8pt;
			content: "Confidential"; 	
		}

		
	}

save above code as .css file, and then upload into your static resource name as "ExpensePDF", and then add the style in your page

 

<apex:page standardController="Expenses__c" extensions="PDFGenerator" renderAs="pdf">
<apex:stylesheet value="{!$Resource.ExpensePDF}"/> 

 

This was selected as the best answer
Semira@gmail.comSemira@gmail.com

Thanks that was perfect!