1

I have developed a visualforce page which contains a button to download the content of the visualforce page as pdf. When I click on the button, a pdf file is downloaded but when I open the file it shows an error

Failed to load PDF document RELOAD".

Also, when I open the file with word it opens up with the data in it but I want to save and open this in a pdf format.

How can I resolve this problem?

Below mentioned is the page code :-

<apex:page standardController="Quote" ContentType="application/pdf#QuoteDownloaded.pdf" showHeader="false" sidebar="false" extensions="CustomPdfForController" cache="false" >
    <apex:form>
        <!--body of the pdf -->
    </apex:form>
</apex:page>
  • Your mentioned page is not rendered as pdf? How can we reproduce the issue? – Raul Oct 23 '17 at 10:49
  • Refer this link: why can't i use contentType as application/pdf in visualforce page – user50036 Oct 23 '17 at 11:09
  • @RahulSharma, when we use renderAs="pdf" then a page will open with the pdf file on the browser, I want to download the file directly instead opening it on a browser. also to reproduce the issue use the above code and provide some data inside the form. – Jitesh Goel Oct 23 '17 at 11:35
0

You need to use the attribute renderAs="pdf" instead of ContentType="application/pdf#QuoteDownloaded.pdf"

So your code will change to:

<apex:page standardController="Quote" renderAs="pdf" showHeader="false" sidebar="false" extensions="CustomPdfForController" cache="false" >
    <apex:form>
        <!--body of the pdf -->
    </apex:form>
</apex:page>

Why ContentType cannot be used. You can find the answer here.

0

@Jitesh, If you want to download the pdf instead of opening it on a browser, HTML 5 provides you with 'download' attribute on href tag which can be used as follows:

<apex:page  docType="html-5.0" .....>

<a download='{!pdfname}' href="{!pdfBlobString}">

</apex:page>

where

String blobVal = EncodingUtil.base64Encode(pdfbody);  
String pdfBlobString = 'data:application/pdf;content-disposition:attachment;base64,'+blobVal;

However, this download attribute is supported only in Chrome/Firefox and not on IE even though there is a workaround for IE.

Please let me know if this is what you were looking for and I can provide you with the links to the workaround for IE.

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.