While i m doing like the following ,i m getting msg like :

failed to load pdf

<apex:page standardcontroller="Account"  sidebar="false"
        showHeader="false" contentType="application/pdf">
<apex:pageBlock title="Contacts">
<apex:pageBlockTable value="{!Account.contacts}" var="contact">
<apex:column value="{!contact.name}"/>
<apex:column value="{!contact.MailingCity}"/>
<apex:column value="{!contact.phone}"/>

It should be rather

apex:page renderAs="pdf"

full spec for renderAs here


In addition to the answer provided by @BigBallOfMud, you'll want to look at Best Practices for Rendering PDFs as <apex pageBlock> and <apex pageBlockTable> are both listed as * Components That Are Unsafe to Use in a PDF. *


There are differences in Visualforce rendering when using renderAs and ContentType:-

when we set renderAs = PDF, it triggers Visualforce engine to generate PDF from page's resultant HTML. In plain words, this triggers conversion of HTML to PDF data (binary)

when we set contentType = application/pdf, then it only impacts the html response's HTTP header, which is used by browser to display files according to their mime-type. This is mostly used for mime-types wherein browser can open the file in appropriate application for e.g. Ms-Excel etc. In plain words, it just renders content in appropriate client application (driven by browser)

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.