title: Drive API - encode pdf string file to base64
body: <p>I'm using the Drive API, particularly the Export functionality <a href="https://developers.google.com/drive/v3/reference/files/export" rel="nofollow noreferrer">https://developers.google.com/drive/v3/reference/files/export</a> to transform a Google Doc to pdf and download it.</p>
  
  <pre><code>                $http.get('https://www.googleapis.com/drive/v3/files/' + id + '/export?mimeType=application%2Fpdf',
              {
                  headers: { Authorization: 'Bearer ' + user.token }
              }).then(function (res) {
  
                      var fileReader = new FileReader();
                      var blob = new Blob([res.data], { type: 'application/pdf' });
  
                      fileReader.onloadend = function () {
                          console.log(fileReader.result);
                      };
  
                      fileReader.readAsDataURL(blob);
              });
  </code></pre>
  
  <p>I'm using that piece of code (AngularJS), on the console I can see something converted, but when I try to render it, I have an error. The render functionality is working fine because I'm rendering other base64 pdf (not downloaded from Google API) and it works.</p>
  
  <p>The thing is, in the response from Google I have a string like:</p>
  
  <blockquote>
    <p>PDF-1.5↵%    ↵2 0 obj↵&lt;&lt; /Linearized 1 /L 22642
    /…tream↵endob......................."</p>
  </blockquote>
  
  <p>How can I do to convert that result into a base64 encoded pdf string? No matter if the conversion is on the client side, or even in the server side with NodeJS.</p>
  
  <p>Thanks!</p>