Print this page

How can I display a blob as pdf on a visualforce page?

Knowledge Article Number 000044612
Description I would like to display the content of a pdf file on a visualforce page.
How can I achieve this requirement if the pdf is stored as blob value in the controller?
Resolution The following example demonstrates how to implement this requirement:

Visualforce Page:
<apex:page controller="ViewPdf">
	<iframe src="data:{!att.ContentType};base64,{!pdf}" ></iframe>
*Note: "data:" URI might not be supported globally in all browsers. For example, in IE, data: URI is not supported for <iframe>;

public class ViewPdf {
    public Attachment att {
        get {
            if (att == null) {
                att = [SELECT Body, ContentType, Name FROM Attachment WHERE ID = '00PG0000004COZU'];
            return att;
        private set;
    public String pdf {
        get {
            return EncodingUtil.Base64Encode(att.body);


promote demote