title: Create PDF from a string in Google Apps Script
body: <p>I am sure this is again something I am not getting because I don't get a general concept. I am trying to create a PDF in Google Drive from a String I have previously constructed.</p>
  
  <pre><code>var oPdfCreator = {
      hFolderHandle: DocsList.getFolderById('0B1rbQnVtcj5CNWNmekFWMG9DZzA'),
      hPdfHandle: "",
  
      mToastFeedback: function () {
        SpreadsheetApp.getActiveSpreadsheet().toast('Finished');
      }
  };
  
  oPdfCreator.hPdfHandle = oPdfCreator.hFolderHandle.createFile('test.pdf',   Utilities.newBlob(oInvoice.sInvoiceBody).getBytes(), 'application/pdf');
  </code></pre>
  
  <p>This does not work, the PDF is malformed and I cannot helpt to start wonder if I didn't get the concept.</p>
  
  <p>Thanks again for your answers.</p>
  
  <hr>
  
  <p>Ok the answer put me on the right track. It was really really close to what I wanted to do, I hoped to be able to directly create a blob with the pdf content, but I realised this is much easier and readable. And we all agree readable code is better!</p>
  
  <pre><code>var oPdfCreator = {
    hFolderHandle: DocsList.getFolderById('0B1rbQnVtcj5CNWNmekFWMG9DZzA'),
    hTempHtmlHandle: "",
    hPdfHandle: "",
  
    mToastFeedback: function () {
        SpreadsheetApp.getActiveSpreadsheet().toast('Finished');
    }
  };
  oPdfCreator.hTempHtmlHandle = oPdfCreator.hFolderHandle.createFile('test.html',  oInvoice.sInvoiceBody, 'text/html');
  oPdfCreator.hPdfHandle = oPdfCreator.hFolderHandle.createFile(oPdfCreator.hTempHtmlHandle.getAs('application/pdf')).rename('test.pdf');
  DocsList.getFileById(oPdfCreator.hTempHtmlHandle.getId()).setTrashed(true);
  
  function fProcessRequest () {
    oInvoice.mProcessInvoice();
    oPdfCreator.mToastFeedback();
  }
  </code></pre>