+ Start a Discussion
GoForceGoGoForceGo 

Printable View of a detail page

I want a printable view of a detail page. The "printable view" standard option doesn't work because I want a logo and I don't want the top right links (close window, print this page, expand all, collapse all.

 

I am trying a quick and dirty renderAs pdf VF page, but the styling is all messed up - the documentation explicitly says  <apex:detail> is unsafe.

 

I don't want to list out each field of the object - since when you add new fields or modify the screen layout, one would have to modify this VF page as well. I tried a few <apex:page> options , such as standardStyleSheets = true, showHeader = false) etc, but none of it works.

 

Is there a trick someone knows which will improve the styling for the code below?

 

 

<apex:page standardController="CObject__c" renderAs="pdf">
<apex:detail relatedList="false"/>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
GoForceGoGoForceGo

So I managed to make it work. The first thing I did was to explicity add salesforce style sheets. Hiding buttons was more problematic - I could hide them when rendered as html, but the pdf version rendered an empty boxes. When I put visibility:hidden in the <head> block, it worked. display:none does NOT work!

 

<apex:page standardController="CObject__c" renderAs="pdf" showHeader="false">
<head>
<style type="text/css">
input {
    visibility: hidden; 
} 
.mainTitle {
    visibility: hidden; 
}
</style>
</head>
<apex:stylesheet value="/sCSS/24.0/sprites/1331837151000/Theme3/default/elements.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1331837151000/Theme3/default/common.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1330620696000/Theme3/dStandard.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1333395518000/Theme3/00DQ0000000HrPa/00580000001ja9P/dCustom0.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1331837151000/Theme3/default/extended.css"/>
<apex:image value="{!imageURL}"/>
<apex:outputPanel layout="block" style="font-size:30px;font-weight:bold;margin-top:20px">
<apex:outputText value="{!CObject__c.Name}"/>
</apex:outputPanel>
<apex:detail  relatedList="false"/>
</apex:page>

 

All Answers

GoForceGoGoForceGo

So I managed to make it work. The first thing I did was to explicity add salesforce style sheets. Hiding buttons was more problematic - I could hide them when rendered as html, but the pdf version rendered an empty boxes. When I put visibility:hidden in the <head> block, it worked. display:none does NOT work!

 

<apex:page standardController="CObject__c" renderAs="pdf" showHeader="false">
<head>
<style type="text/css">
input {
    visibility: hidden; 
} 
.mainTitle {
    visibility: hidden; 
}
</style>
</head>
<apex:stylesheet value="/sCSS/24.0/sprites/1331837151000/Theme3/default/elements.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1331837151000/Theme3/default/common.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1330620696000/Theme3/dStandard.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1333395518000/Theme3/00DQ0000000HrPa/00580000001ja9P/dCustom0.css"/>
<apex:stylesheet value="/sCSS/24.0/sprites/1331837151000/Theme3/default/extended.css"/>
<apex:image value="{!imageURL}"/>
<apex:outputPanel layout="block" style="font-size:30px;font-weight:bold;margin-top:20px">
<apex:outputText value="{!CObject__c.Name}"/>
</apex:outputPanel>
<apex:detail  relatedList="false"/>
</apex:page>

 

This was selected as the best answer
jbardetjbardet

This code is great and I'll be using it on a handful of objects to quickly add much needed printing funcationality.

 

But I have almost no VF skils.

 

Is there any additional code I can add to amend the output of simply writing:

 

<apex:detail  relatedList="false"/>

Specifically, I'd like to know how to:

 

1) Exclude particular fields on the rendered PDF?

2) Exclude particular field labels? (ie on Activity, when creating a PDF for emails, i really don't need to see "Comments" label beside the email.

3) Change the location of field labels? Can they be moved to above and in line with the field data, rather than to the left margin and centered (vertically).

 

I'm looking for a solution that is scalable to other objects if possible, only needing to change, say, my excluded items.

 

Thank you so much!

 

Jeremy

jbardet@gmail.com