function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shruti VishShruti Vish 

I want to open pdf document in lightning component

I want to open the pdf in lightning component how it can be done please help me out for this 
Bhavya Jain 17Bhavya Jain 17
Hi Shradha ,

I don't think its feasible. Also please give a brief about what you are trying to achieve. May be i will be able to resolve.

Thanks & Regards 

Bhavya Jain
Shruti VishShruti Vish
I have created the lightning component where i have button on click of that i am tring to download file which is stored in document in one folder below is my code

public class DownloadAttachment {
    @AuraEnabled
 public static string DownloadAttachmentMethod(Id DownloadAttachmentID)
   {
   Document documents = [SELECT Id, FolderId, Folder.Name FROM Document WHERE Folder.Name like 'SharedDocuments%' LIMIT 1];  
    System.Debug('Document Id :'+ documents.Id);
   
    String fullFileURL = URL.getSalesforceBaseUrl().toExternalForm();
    String URlDownload = fullFileURL+'/sfc/servlet.shepherd/version/download/'+documents.Id;
    system.debug('Download URL:' +URlDownload);
    return URlDownload;
    } 
}
<aura:component controller="DownloadAttachment" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="Document" type="String" />

<a href="" data-id="01528000003UFIUAA4"  onclick = "{!c.downloadfile}" >Download</a>    
</aura:component>

({
    downloadfile : function (component, event, helper){                 
    var id = event.target.getAttribute("data-id");       
    alert('Document ID:' +id);
    var actiondownload = component.get("c.DownloadAttachmentMethod");

    actiondownload.setParams({
        "DownloadAttachmentID": id
    });

      actiondownload.setCallback(this, function(b){
        component.set("v.Document", b.getReturnValue());
          console.log('hi'+b.getReturnValue());
        var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": b.getReturnValue()
    });
    urlEvent.fire();
    
    });
         $A.enqueueAction(actiondownload);
    }
})
rishabh rathor 18rishabh rathor 18
whta is  :- data-id="01528000003UFIUAA4 ?