+ Start a Discussion
miha198206miha198206 

Can't apply css styles when renderAs="PDF"

I try to create the page from here: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_page.htm

 

I've made a page:

 

 

<apex:page renderAs="pdf">
    <style> body { font-family: Arial Unicode MS; font-size:72px;} </style>
    <h1>Congratulations</h1>
    <p>This is your new PDF</p>
</apex:page>

 

 

But styles was not applied. How can I use css in PDF? Why does this code sample not work for me?

 

Thanks a lot.

 

Mikhail

Best Answer chosen by Admin (Salesforce Developers) 
SSRS2SSRS2

Put your style tag within the head tag

 

<apex:page renderAs="pdf">
  <head>
    <style> body { font-family: Arial Unicode MS; font-size:72px;} </style>
  </head>  
  <h1>Congratulations</h1>
  <p>This is your new PDF</p>
</apex:page>

 

-Suresh

 

All Answers

SSRS2SSRS2

Put your style tag within the head tag

 

<apex:page renderAs="pdf">
  <head>
    <style> body { font-family: Arial Unicode MS; font-size:72px;} </style>
  </head>  
  <h1>Congratulations</h1>
  <p>This is your new PDF</p>
</apex:page>

 

-Suresh

 

This was selected as the best answer
miha198206miha198206

Thanks a lot.

 

I've try it with head tag before. But now I've noticed that sometimes I should click ctrl+F5 to refresh changes in generated PDF file.

APathakAPathak

Thanks Suresh that solved my problem too!

HJPHJP

Starting from API version 27 do NOT use a <html> tag as it will be included by SF.

 

I found this issue when moving a well CSS formatted PDF page from the sandbox to the live system, and the formatting was gone in the live system due to the update in the API version.

Jean DuqueJean Duque
Hey guys just to make a note, starting from API 28 to get this working please add "applyHtmlTag=false" to your code:
 
<apex:page standardController="YourController" showHeader="false" applyHtmlTag="false" renderAs="pdf">