I am trying to coverting vf page as pdf format,for that am usinf contentType="application/pdf"

<apex:page standardController="Opportunity"   extensions="PDFcontroller"  
                                                            contentType="application/pdf" >

while executing this am getting error as


is this correct approach?


If you want to display VF page as pdf format then use renderAs


<!-- Page: -->
<apex:page renderAs="pdf">
    <style> body { font-family: 'Arial Unicode MS'; } </style>
    <p>This is your new PDF</p>

// Note that if you have CSS and you want to render asPDF your CSS should be in a static ressource otherwise it will not work.

  • if i use renderAs ,table format data not displaying in pdf document.. – lathish Apr 11 '16 at 7:17
  • @lathish without renderAs="pdf" data displaying ? – Ratan Paul Apr 11 '16 at 7:19
  • yes ,data displaying.... – lathish Apr 11 '16 at 7:23
  • 3
    @lathish then I think issue with you CSS property.. may be that is causing .. – Ratan Paul Apr 11 '16 at 7:24
  • 1
    @lathish can you remove the css property from table and then try.. – Ratan Paul Apr 11 '16 at 7:27

As far as I know, rendering a Visualforce page as a PDF is a big pain. Salesforce uses flying saucer as its PDF generator engine and it have very much limitations.

Visualforce PDF Rendering Considerations and Limitations lists the consideration and limitations you should keep in mind while trying to show Visualforce pages as PDF.

Few points I like to point are:

  1. Wrapping long texts without space or dash will go out of PDF.
  2. Shouldn't use input components such as inputField, inputCheckbox.
  3. Shouldn't use any component which uses javascript such as actionSupport, actionFunction.
  4. Default Salesforce styling won't get applied when rendered as PDF. So you should play with css yourself to get the results. This is big drawback for table structure such as pageblocktable.

So I would recommend you to follow a strategy of bottom up like switching off standardstylesheet in page and create the Visualforce page by yourself, so that it will appear same when rendered as PDF.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.