title: Displaying REST API response as inline pdf (not downloaded file)
body: <p>I am using force.com and I have to embed a chatter pdf file inline in the page (not as a download). I have no direct access link to the pdf and the only way to get at the file itself is via a rest call for eg</p>
  <p>/services/files/fileid/content</p>
  <p>This returns binary pdf data which I then want to embed in the webpage.
  Based on various Stack Overflow answers I got some good ideas how to do this and the pdf opens in the page except that its blank - ie it has no content. It has the correct number of pages but no text is displaying.</p>
  <p>If I run fiddler while this request is happening, and then save the response as a file the pdf looks great. But for some reason the response coming to the ajax request and being delivered to the browser is no good. I suspect it has something to do with some kind of encoding that I need to be doing in order to properly deliver the pdf data to the browser.</p>
  <p><strong>Would really appreciate any suggestions here or even different approaches - have tried many different ones and this is the closest I got, but am blocked again.</strong></p>
  <p>This is my code making the API call and displaying in the browser:</p>
  <pre><code>$.ajax({
  url: &quot;/services/data/v35.0/chatter/files/069R0000000O8reIAC/content?versionNumber=1&quot;,
  headers: {&quot;Authorization&quot;: &quot;OAuth xxxxxxxxxxxx&quot;},
  contentType: &quot;application/pdf&quot;,
  success: function(data) 
  { 
      
        var blob = new Blob([data], {type: &quot;application/pdf&quot;});
        window.open(URL.createObjectURL(blob));     
  
  },
   type: 'GET'
  });
  </code></pre>
  <p>This opens up a page that looks like this: (note: it has the correct number of pages)
  <a href="https://i.stack.imgur.com/CbgBL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CbgBL.png" alt="enter image description here" /></a></p>
  <p>Even though when I look at fiddler on that request and save the response body as a file the pdf is good!</p>