Hi,
Here in the following example i am using one custom component ,visualforce page and an extension.Here the custom component is used to display preview of attachment by getting the id from visualforce page where it is included.In this component i am using "Object" ,"embed" html tags to show preview of attachment.
Component Code:
===============
Here in the following example i am using one custom component ,visualforce page and an extension.Here the custom component is used to display preview of attachment by getting the id from visualforce page where it is included.In this component i am using "Object" ,"embed" html tags to show preview of attachment.
Component Code:
===============
<apex:component > <apex:attribute name="height" type="String" description="TODO: Describe me"/> <apex:attribute name="width" type="String" description="TODO: Describe me"/> <apex:attribute name="value" type="String" description="TODO: Describe me"/> <object data="/servlet/servlet.FileDownload?file={!value}" type="application/pdf" width="{!width}" height="{!height}"> <embed src="/servlet/servlet.FileDownload?file={!value}" width="{!width}" height="{!height}"/> </object > </apex:component>
Visualforce Page:
=============
<apex:page standardcontroller="Attachment" extensions="Attachradiocls1" sidebar="false">
<h1 style="padding:10px;width:100%;float:left; font-size:24px; color:#015ba7;">ABC Company</h1>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="width: 283px; vertical-align:top; background:#CCC;border-right: #F0F0F0 2px solid;">
<div style="margin:20px;">
<h1>Contact Info</h1>
<table>
<tr>
<td>
Contact Name:
</td>
<td>
{!contobj.Name}
</td>
</tr>
<tr>
<td>
Contact Email:
</td>
<td>
{!contobj.Email}
</td>
</tr>
<tr>
<td>
Lead Source:
</td>
<td>
{!contobj.Leadsource}
</td>
</tr>
</table>
</div>
</td>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<c:Pdfcomponent value="{!attachment.id}" width="824px" height="1135px"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</apex:page>
Extension Code:
==============
public with sharing class Attachradiocls1 {
public Contact contobj{get;set;}
public Attachradiocls1 (ApexPages.Standardcontroller stdcontroller){
contobj=new Contact();
String id=ApexPages.CurrentPage().getParameters().get('id');
if(id!=null && id!=''){
Attachment att=[select id,name,parentId,body from attachment where id=:id];
//body=att.body.tostring();
contobj=[select id,name,Email,LeadSource from Contact where id=:att.parentId];
}
}
}
Output:
======
Great Post Balaji.. awesome..!!!
ReplyDeleteThis will preview only PDF Attachment or any Attachment as PDF.?
ReplyDeleteHi Sunil,
ReplyDeleteYou need to specify the type in object tag according to your attachment type.
It will be usefull to get mime types
ReplyDeletehttp://www.sitepoint.com/web-foundations/mime-types-complete-list/
Nice Info...
ReplyDeletegetting error like preview unavailable..,,could you please help on this?
ReplyDeleteI couldn't get it work? could you please assist, where can I use these page and component, if I want to use it in a custom object layout what should I need to follow?
ReplyDelete