Why can't i use contentType as application/pdf in visualforce page?

1.4K    Asked by BenButler in Salesforce , Asked on Jul 22, 2021

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

failed to load pdf

How to create a PDF content type?

The MIME type for a PDF file is "application/pdf". To open a PDF file in a servlet, you set the content type in the response header to "application/pdf" : // MIME type for pdf doc res. setContentType( "application/pdf" )

Answered by bhagwati dubey

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 PDF 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) Steps to create PDF content type: The MIME type for a PDF file is "application/pdf". To open a PDF file in a servlet, you set the content type in the response header to "application/pdf" : // MIME type for pdf doc res. setContentType( "application/pdf" )



Your Answer

Interviews

Parent Categories