0

I am trying this below code to view all the attachments in a single window, but i am unable to do it. I am able to view only one attachment at a time.

Is there any solution or workaround where i am view all the attachments in a single window.

Apex Class -

public class AttachmentClass{
public string attachmentid {get; set;}
    public List<Attachment> atch {get; set;}
public AttachmentClass(){
    atch = new List<Attachment>();

    atch = [select Id from Attachment];
    For(Attachment a:atch){

       attachmentid=a.Id; 
    }
  //attachmentid='00P9000001HdVtc';
}
} 

vf page -

<apex:page controller="AttachmentClass">
<a href="{!URLFOR($Action.Attachment.Download, attachmentId)}" class="btn btn-info">
 <span class="glyphicon glyphicon-save-file"></span> Download </a>
<br/><br/>
    <apex:repeat value="{!atch}" var="a">
<a href="#" class="btn btn-info" onclick="return window.open('{!URLFOR($Action.Attachment.Download, a.Id)}','_top');">
<span class="glyphicon glyphicon-save-file"></span> Preview</a>
        </apex:repeat>
</apex:page>

1 Answer 1

0

Can you try using iframe in the page instead ? try creating a page with iframes, and probably style it to look better.

Something like below should get you all the attachments

<apex:repeat value="{!atch}" var="a">
    <iframe src="{!URLFOR($Action.Attachment.Download, a.Id)}"/>
</apex:page>
3
  • Hi Avi..Thanks for the reply.. Can we display attachment as a pdf..instead of iframe... Commented Sep 29, 2017 at 11:42
  • I guess those iframe will actually display the pdf files if they are pdfs, did you give it a try ? else you can give PDF.js a try mozilla.github.io/pdf.js
    – Avidev9
    Commented Sep 29, 2017 at 12:45
  • Hi Avi.. I have never used PDF.js... Do u have any sample which is used in vf pages.. Commented Sep 29, 2017 at 13:53

You must log in to answer this question.

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