2

I want to create a custom lightning component to view pdf files; Pdf files are stored in my attachments salesfoce object;

To do that, i have just, create simple component:

<aura:component controller="CustomAttachmentViewerController"  implements="forceCommunity:availableForAllPageTypes" access="global" >
<ltng:require styles="/resource/SLDS080/assets/styles/salesforce-lightning-design-system.css" />
<aura:attribute name="customAttachmentId" type="String" default="SomeTestID"/>
<aura:attribute name="attachmentUrl" type="String"/>
<aura:attribute name="attId" type="String"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <head>
    </head>
    <body>    
        <div class="slds">
            <iframe style="border: 1px solid" src="{!v.attachmentUrl}" type="application/pdf"/>
        </div>
    </body>
</html>              

after that, in my doInit handler, i retreive the attachmentUrl from my apex controller; and assign it to v.attachmentUrl;

The apex code that return attachmentUrl:

attachmentUrl = URL.getSalesforceBaseUrl().toExternalForm() 
                    + '/servlet/servlet.FileDownload?file=' + attachmentId;

The issue that i have when i test this, is that the file is downloaded instead of displayed in the iframe;

One precision, my lightning component is used inside visualforce page, not in lightning app;

Thanks for helping;

1 Answer 1

3

Your attachment will most likely be stored as a blob, not as a string. For that reason, you'l need to use getContentAsPDF() to display it on your Visualforce page, which BTW was definitely the way to go in designing your component.

0

You must log in to answer this question.

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