title: Downloading PDF from API via Javascript
body: <p>i am using vue.js and found some good examples how to realize this.</p>
  
  <p>Currently my API is returning a test-pdf:</p>
  
  <pre><code>    $snappy = App::make('snappy.pdf');
  
      $html = '&lt;h1&gt;Bill&lt;/h1&gt;&lt;p&gt;You owe me money, dude.&lt;/p&gt;';
  
      return Response(
          $snappy-&gt;getOutputFromHtml($html),
          200,
          array(
              'Content-Type'          =&gt; 'application/pdf',
              'Content-Disposition'   =&gt; 'attachment; filename="file.pdf"'
          )
      );
  </code></pre>
  
  <p>Downloading the Content via Postman works well.</p>
  
  <p>I managed the JS-part like this:</p>
  
  <pre><code>  export const InvoiceService = {
    get(slug) {
      return ApiService.get("invoice", slug);
    },
    downloadPdf(slug) {
      return ApiService.get(`pdf/invoice`, slug, {
        responseType: 'arraybuffer'
      });
    }
  };
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>InvoiceService.downloadPdf(invoiceId)
          .then(({ data }) =&gt; {
            let blob = new Blob([data], {
              type: "application/pdf"
            });
            FileSaver.saveAs(blob, "invoice.pdf");
          })
          .catch(error =&gt; {
            throw new Error(error);
          });
  </code></pre>
  
  <p>The download works fine but the file downloaded via js seems to be corruped (PDF wont show):
  <a href="https://i.stack.imgur.com/C3yxd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C3yxd.png" alt="enter image description here"></a></p>
  
  <p>The green marked text is the content of the working pdf.</p>
  
  <p>I think something is messed up with the charset, but i ran out of Ideas :(</p>
  
  <p>Hopefully someone can give me a hint - It drives me nuts :)</p>
  
  <p>Best regards - Alex</p>