Play Games

Search This Blog

Saturday, January 4, 2014

Generation of pdf,word and excel files from visualforce page

We can generate pdf , word and excel files from visualforce page.Visualforce page is used to display the contents.

Generation of pdf file:
If u want to generate pdf file then u can use "renderAs" attribute of <apex:page> tag.
For example the below sample vf code will generate pdf file.

<apex:page renderAs="pdf">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->
</apex:page>

When we run the above sample code,the output will be a pdf file as shown in below image.

U can observe from above code I  used  renderAs="pdf" in <apex:page>  to generate pdf file.

Generation of Ms-word file:
If u want to generate word file then u can use contentType="application/vnd.msword" attribute of <apex:page> tag.
For example the below sample vf code will generate word file.

<apex:page contentType="application/vnd.msword">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->
</apex:page>

When we run the above sample code,the output will be a word  file as shown in below image.
 Generation of Ms-Excel File:
If u want to generate Excel file then u can use contentType="application/vnd.ms-excel" attribute of <apex:page> tag.
For example the below sample vf code will generate Excel file.

<apex:page contentType="application/vnd.ms-excel">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page
  <!-- End Default Content REMOVE THIS -->
</apex:page>

When we run the above sample code,the output will be a Excel file as shown in below image.


No comments:

Post a Comment