You need to sign in to do that
Don't have an account?

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
You need to sign in to do that
Don't have an account?
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
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);
}
})