Render a Visualforce Page as a PDF File
Render a Visualforce Page as a PDF File
You can generate a downloadable, printable PDF file of a Visualforce page using the PDF rendering service.
Convert a page to PDF by changing the <apex:page> tag.
<apex:page renderAs="pdf">
Example :
Apex Class:
public class WebAttachMentApexClass {
public List<Contact> cs{get; set;}
public WebAttachMentApexClass()
{
cs = new List<Contact>();
for (Contact c : [Select id, Name from Contact])
{
cs.add(c);
}
}
}
VisualForce Pge:
<apex:page controller="WebAttachMentApexClass" showHeader="false" renderAs="pdf">
<apex:pageBlock title="Export Results" >
<table border="1" cellpadding="6" width="100%">
<tr>
<th>ContactId</th>
<th>Contact Name</th>
</tr>
<apex:repeat value="{!cs}" var="contact">
<tr>
<td>
<apex:outputText value="{!contact.ID}" style="width:50%"/>
</td>
<td>
<apex:outputText value="{!contact.Name}"/>
</td>
</tr>
</apex:repeat>
</table>
</apex:pageBlock>
</apex:page>
Result :
Comments
Post a Comment