Is this post still valid as a solution to download a pdf from third-party site, then displaying it in a Visualforce page?
This is what I'm doing in my code:
Visualforce page
<apex:page controller="pdfDownloadController" sidebar="false" showHeader="false" contentType="application/pdf">
<script>
window.location.href = "data:application/pdf;base64,{!pdf}";
</script>
</apex:page>
Apex Class
public class pdfDownloadController {
public String getPdf() {
HttpRequest req = new HttpRequest();
req.setEndpoint('https://www.irs.gov/pub/irs-pdf/fw4.pdf');
req.setMethod('GET');
// Make call
Http client = new Http();
HttpResponse rsp = client.send(req);
return rsp.getBody();
}
}
This is what loads when I go to this Visualforce page in lightning:
It doesn't appear to work when I go to classic either.
UPDATE:
As suggested by sfdcfox suggested, I used his method to display the pdf. That didn't work, but I did see these errors in the web console (Firefox):
I tried Chrome got a different browser response:
This what I get in the debug log from the response body. It looks like a pdf: