title: Passing a pdf from Django backend to Angular frontend
body: <p>I haven't been able to make any of the solutions to similar problems work for my case.
  I would like to load a pdf from filesystem with django and return it via an API call to Angular so that it can be displayed. My Django code is pretty much:</p>
  <pre><code>class LoadPdfViewSet(views.APIView):
      def get(self, request):
          # some code here here
          response = FileResponse(open(path_to_pdf, 'rb').read())
          response.headers = {   
              'Content-Type': 'application/pdf',
              'Content-Disposition': 'attachment;filename=&quot;report.pdf&quot;',
          }
          response.as_attachment = True
          return response
  </code></pre>
  <p>while on the Angular side I have a service that does this:</p>
  <pre><code>export class LoadPdfService {
      constructor(
          private http: HttpClient
      ) {}
  
      getPdf(): Observable&lt;Blob&gt; {
          const params = new HttpParams({
              fromObject: { 
                  responsetype: 'arraybuffer' 
                  // other stuff here
              }
          })
          return self.http.get&lt;Blob&gt;(loadpdf_api_url, {params}).pipe(catchError(self.myErrorHandler))
      }
  }
  </code></pre>
  <p>and a component that tries to open the pdf like this:</p>
  <pre><code>export class MyComponent {
      constructor(
          public loadPdfService: LoadPdfService
      ) {}
  
      download_pdf() {
          let call = self.loadPdfService.getPdf();
          call.subscribe( (response:Blob) =&gt; {
              if (window.navigator &amp;&amp; window.navigator.msSaveOrOpenBlob) { // for IE
                  window.navigator.msSaveOrOpenBlob(blob, &quot;report.pdf&quot;);
              } else {
                  let pdfUrl = URL.createObjectURL(blob)
                  window.open(pdfUrl, '_blank')
                  URL.revokeObjectURL(pdfUrl);    
              }            
          }
      }
  }
  </code></pre>
  <p>but nothing happens. I have also tried using different responses and passthrough renderers on the django side, and <code>Observable&lt;Response&gt;</code> and <code>.then()</code> callbacks like</p>
  <pre><code>response.arrayBuffer().then(buffer =&gt; new Blob([buffer], {type: 'application/pdf'}))
  </code></pre>
  <p>on the Angular side. Sometimes I have managed to get the new window/tab to open but no pdf could be displayed.</p>