You need to sign in to do that
Don't have an account?
Controlling layout and style for VisualForce pages rendered as a PDF
Is there a way to do this?
I have several VisualForce pages I am using the generate PDF documents. I find that I cannot seem to control simple layout and style items, such as the format for table headers and the type of font used for the document, using in-line CSS when these pages render as PDFs. I am easily able to control these elements using in-line CSS when I render these pages as HTML.
This is important as several VisualForce elements do not let me define style attributes for an element. I have to use in-line CSS classes to pass to the element's appropriate 'style' attribute. An example of this is the 'apex: DataTable'element, which requires I pass it a CSS class to the 'headerClass' and 'rowClasses' attributes.
However, it is as if the PDF rendering engine is ignoring my in-line CSS. Is there any way to force the PDF engine to use my CSS, so I can get a PDF output which matches my HTML output?
<apex:stylesheet value="{!URLFOR($Resource.quoteStyle)}"/>
All Answers
<apex:stylesheet value="{!URLFOR($Resource.quoteStyle)}"/>
Thanks for the response. I just had a chance to test it, and it is working for most components.
However, I have need to color alternate rows in the 'apex: Datatable' element. I am adding two classes to the CSS to handle this, and am passing these to the 'RowClasses' attribute for my Datatable, seen here:
<apex:dataTable value="{!License_Invoice__c.Invoice_Products__r}" width="100%" rules="all" border="1" cellpadding="2" var="product" rowClasses="even,odd" headerClass="tableHeader">
The CSS classes look as follows:
.odd { background-color: White;} .even {background-color: LightSteelBlue;}
This renders fine in the HTML version of this page, but not in the PDF. Even weirder, the formatting defined in the class in the 'headerClass' attribute is rendering appropriately.
What's going wrong? Am I simply selecting a color for the rows which is not supported in PDFs?