For our project, we need to get a PDF via API from an external private filestore, and display it within a Lightning Component. With the blob that is returned, if I set that to the src of an iFrame, it works in some browsers, but not Chrome, due to CSP issues. Same problem if I try a base64 approach. Also, unfortunately srcdoc, embed, and object tags are not supported in Salesforce.

EDIT: I should also add that I tried PDF.js, but couldn't get it to work due to LockerService.

What would be the best approach to getting this file to display?

Is there a way to manually edit the CSP header for things like object-src to allow Blob? Does Salesforce have a built in way to display blob data? Is there an easy way with Apex that I could turn the PDF into an image the same way Salesforce generates previews for content documents?

  • Are you building a Lightning component, a Visualforce page ... ? – David Reed Feb 14 '19 at 15:10
  • Ah sorry, a Lightning component. I'll update original question – Luke Feb 14 '19 at 15:10
  • Are you storing this file in Salesforce or this is temporary and you only want to display it? – Jayant Das Feb 14 '19 at 15:31
  • @JayantDas Temporary and just want to display it. We're getting the file from an external private filestore. – Luke Feb 14 '19 at 15:50
  • Did you find the solution? if so please share your ideas – SFDC Apr 26 '19 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.