0

It is possible to show the first page of an PDF attachment on a visualforce page like a preview?

I have a custom object with some information and a link to a PDF file which is stored in salesforce. I have a list of all these items and I wanna show the first page of the PDF.

EDIT

<object
    data="/servlet/servlet.FileDownload?file=0698E0000008oIpQAI"
    width="100%"
    style="height: 100px; border: 1px solid grey;" 
    type="application/pdf"
    />

I add this code, but It doesnt work, I just see the border. The file is stored as file and attachment in the custom object.

1
  • Maybe the document you're trying to present is a doc and not pdf? Most ids of pdfs in SF start with 015 and not with 069.. Jun 18, 2017 at 13:47

1 Answer 1

5

I have used the object tag to display a PDF static resource so I assume this will work for your PDF link:

<object
        data="{!linkToPdfFile}"
        width="100%"
        style="height: 500px; border: 1px solid grey;" 
        type="application/pdf"
        />

PS

Based on the comment thread, I think this is what worked for peXeq:

<apex:iframe src="/servlet/servlet.FileDownload?file={!attachment.id}"/>
5
  • I deleted my answer your answer seems more appropriate for this context
    – RedDevil
    Jun 17, 2017 at 19:56
  • What kind of link is necessary
    – peXeq
    Jun 18, 2017 at 9:44
  • @peXeq Just had a Google and found <apex:iframe src="/servlet/servlet.FileDownload?file={!attachment.id}"/>; give that a quick try. Not to sure what will work fpr an attachment.
    – Keith C
    Jun 18, 2017 at 12:47
  • @KeithC, this will try to download the document and present it. Jun 18, 2017 at 13:48
  • iframe works fine, for images and pdf documents.
    – peXeq
    Jun 18, 2017 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .