title: Serve PDF file as blob in Google Apps Script
body: <p>I have a google apps script that generates a PDF file. My goal now is to serve that PDF file back to the UI so the user can download or print it. However, the limitation here is that I cannot redirect the user to a Google Drive URL - I need the file to be given to the user on the same page that initiated the file generation. I have seen <a href="https://stackoverflow.com/questions/17072944/google-app-script-display-pdf-on-form-submit">this post</a> which gives a solution to download, but it uses a Google Drive link. Additionally, <a href="https://stackoverflow.com/questions/14021597/how-to-download-created-csv-file-using-google-apps-script">this post</a> and <a href="https://stackoverflow.com/questions/20281272/initiate-a-download-from-google-apps-script?noredirect=1&amp;lq=1">this post</a> mention downloading, but it only works for the given file types, which does not include PDF. </p>
  
  <p>I am able to generate the PDF and blob inside the <a href="https://developers.google.com/apps-script/guides/web" rel="nofollow noreferrer"><code>doGet</code></a> method, but I don't know how to serve it to the UI so the user can then interact with is. Is there a way to pass the blob to the front end and then allow the user to download or print that blob as a PDF?</p>
  
  <pre><code>function doGet(request){    
      var file = generateFile();
      var blob = file.getAs('application/pdf');
      //Goal: return blob to front end so user can download / print
  }
  </code></pre>