You need to sign in to do that
Don't have an account?
juppy
Can I display pdf content in a vf page?
Hi all,
I have a client who has a couple of hundred pdf documents he wants to load into and view in sf - not enough to make it worthwhile using a document storage solution.
I can load a pdf as an attachment, and retrieve that in apex, but cannot get the attachment body to display on a vf page.
Does anyone know if this can be done please - and how to go about it?
Thanks!
If the PDF is downloaded, that rather smacks that the browser doesn't know what to do with it. In mine (google chrome) it displays the PDFs inline.
If you are using the adobe plugin, there's a help page for that at:
http://kb2.adobe.com/cps/328/328233.html
All Answers
I've done this in the past by adding an iframe whose src is the attachment download URL, e.g.
Hi ,
You can display the pdf content in a visual force page by using code snippet below
List<Document> d = [Select id,body, bodyLength, ContentType, Url from Document where Name ='ConsentForm'];
NOTE: ConsentForm is a pdf document which is uploaded in document.
if document or attachment content type is "application/pdf"
string strOrgId = UserInfo.getOrganizationId();
string content = '/servlet/servlet.ImageServer?id=' + Contentdataid + '&oid='+ strOrgId ; PageReference pg = new PageReference(content);
pg.setRedirect(true);
return pg;
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks for the quick response Bob (btw, I enjoyed A Most Peculiar Practice too...)
Had time to try your suggestion, and also SE's suggestion for treating the pdf as a Document, and sadly neither worked for me; the pdf is downloaded, but not displayed in the vf page, which is what I need to do.
I've tried several variants of your code including making the controller an extension of my custom object - full code follows:
public with sharing class SPVFC_ProductLabel
{
public SPVFC_ProductLabel(ApexPages.StandardController sc)
{
}
}
<apex:page standardController="Product_Label__c" extensions="SPVFC_ProductLabel" >
<apex:form >
<apex:repeat value="{!Product_Label__c.Attachments}" var="attachment">
<apex:iframe src="{!URLFOR($Action.Attachment.Download, attachment.Id)}" />
</apex:repeat>
</apex:form>
</apex:page>
Any ideas?
Warmest regards
Mike
If the PDF is downloaded, that rather smacks that the browser doesn't know what to do with it. In mine (google chrome) it displays the PDFs inline.
If you are using the adobe plugin, there's a help page for that at:
http://kb2.adobe.com/cps/328/328233.html