You need to sign in to do that
Don't have an account?
Subha
Display Body of Attachment
Hi
I need to know is it possible to display the content in the Attachment in a VF page as PDF or in any format??? If so can anyone please tell me how to do it.. It is very urgent requirment
The way I've done this in the past is to have an iframe in the page whose src is the attachment URL.
Thank you for the quick reply but can you please send me the code if u dont mind
I tried out this...it is opening a dialog to save or open the doc that I have attached but it is not giving the content of the Attachment to display in the page
Are you pointing to the attachment record itself, or the servlet that returns the attachment content?
<apex:repeat value="{!attachments}" var="attach">
<apex:iframe src="{!attach.Id}" title="Sample" width="718" height="700" />
</apex:repeat>
can you please tell me is this the right way of giving the src????
I think the following should give you what you are looking for:
I tried that but it is giving error.Unkown property String.Id as it is considering attach.Id as String. I even tried with
<apex:iframe src="{!URLFOR($Action.Attachment.Download,{!attach.id})}" title="Sample" width="718" height="700" />
It is also giving a compilation error
You don't need the additional braces around attach.id.
Then it is giving a compile error as Unknown Property:String.Id
That implies that it thinks attach is a string and not an attachment object. Can you post the full code.
<apex:page standardController="eGrant_Proposal__c" extensions="ProposalController" renderAs="PDF" >
<style>
.headerRow .headerStyle{background-color:#638658;color:#FFFFFF}
</style>
<apex:pageBlock title="Proposal">
<apex:form >
<apex:repeat value="{!pdfproposal}" var="proposal">
<apex:outputText value="Date Of Application : "></apex:outputText>
<apex:outputfield value="{!proposal.Date_Of_Application__c}" /><br/>
<apex:outputText value="Name Of Organization : "></apex:outputText>
<apex:outputfield value="{!proposal.Legal_Name_of_Organization__c}" /><br/>
<apex:outputText value="Organization Website : "></apex:outputText>
<apex:outputfield value="{!proposal.Organization_Website__c}" /><br/>
<apex:outputText value="Project Title : "></apex:outputText>
<apex:outputfield value="{!proposal.Project_Title__c}" /><br/>
<apex:outputText value="Address : "></apex:outputText>
<apex:outputfield value="{!proposal.Address__c}"/><br/>
<apex:outputText value="City, State & Zip : "></apex:outputText>
<apex:outputfield value="{!proposal.City_State_Zip__c}"/><br/>
<apex:outputText value="Email : "></apex:outputText>
<apex:outputfield value="{!proposal.Email__c}" /><br/>
<apex:outputText value="Fax Number : "></apex:outputText>
<apex:outputfield value="{!proposal.Fax_Number__c}"/><br/>
<apex:outputText value="Phone Number : "></apex:outputText>
<apex:outputfield value="{!proposal.Phone_Number__c}" /><br/>
<apex:outputText value="Amount Requested : "></apex:outputText>
<apex:outputfield value="{!proposal.Amount_Requested__c}" /><br/>
<apex:outputText value="Total Project Cost : "></apex:outputText>
<apex:outputfield value="{!proposal.Total_Project_Cost__c}" /><br/>
<apex:outputLabel value="The Following are the Attachments for: {!proposal.Legal_Name_of_Organization__c}" rendered="{!isAttachmentAvailable}"></apex:outputLabel>
<br/>
<apex:repeat value="{!attachments}" var="attach">
apex:iframe src="{!URLFOR($Action.Attachment.Download, attach.id)}"/>
</apex:repeat>
</apex:repeat>
</apex:form>
</apex:pageBlock>
</apex:page>
public class ProposalController {
public boolean isAttachmentAvailable;
public eGrant_Proposal__c proposal{get;set;}
public List<Attachment> attachments {get;set;}
public List<eGrant_Proposal__c> getPdfProposal()
{
ID pid = ApexPages.currentPage().getParameters().get('id');
List<eGrant_Proposal__c> proposals = [select Id,Name,proposal.Date_Of_Application__c,proposal.Legal_Name_of_Organization__c,proposal.Organization_Website__c,proposal.Project_Title__c, proposal.Address__c,proposal.City_State_Zip__c,proposal.Email__c,proposal.Fax_Number__c,proposal.Phone_Number__c,proposal.Amount_Requested__c,
proposal.Total_Project_Cost__c from eGrant_Proposal__c proposal where Id =:pid];
attachments = [select Id,Name,Body,ParentId from Attachment where ParentId=:pid];
return proposals;
}
}
Your apex:iframe appears to be missing the opening '<' - is that a cut and paste error?
yes that is missed while cut paste
Do you get the same issue if you don't render the page as pdf? That's the only real difference between your code and mine.
yes Bob.. I have checked that by removing the renderAs=pdf ... But still it is giving a compilation error as Unknown property String.Id
Hi Bob
Sorry there was some issue with the code.. That is why it was displaying that error..
Now I have rectified that and removed the renderAs=PDF but now when I open the VF Page it is asking to save the attachement .. But I need the body of the attachment to display in the VF Page
That is normally because the browser can't display PDF inline. Do you have an appropriate plugin etc on your browser?