title: Can no longer produce PDF from Google Sheets spreadsheet for some of the users
body: <p>For almost a year we have been using the below code to export a Google Sheets sheet (held in <code>theSheetName</code>) to a PDF named as specified in <code>InboundID</code>.</p>
  <p>This last week, one at a time various users can no longer produce the PDF.  I get a failure at the line containing &quot;var newFile = DriveApp.createFile(blob);&quot; with the error being:</p>
  <blockquote>
  <p>&quot;Conversion from text/html to application/pdf failed.&quot;</p>
  </blockquote>
  <p>And sure enough, the <code>UrlFetchApp.fetch</code> is returning HTML instead of a PDF.  Again, only for some users. Does anyone have any thoughts as to why my users might be seeing this?</p>
  <pre><code>function sendPDFToDrive(theSheetName, InboundID) 
  {
    var theSpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
    var theSpreadsheetId = theSpreadSheet.getId();
    var thisSheetId = theSpreadSheet.getSheetByName(theSheetName).getSheetId();  
    var url_base = theSpreadSheet.getUrl().replace(/edit$/,'');
    var theOutFileName = &quot;GASFILE_M_&quot; + (Math.floor(Math.random() * 8997) + 1000) + '.pdf'
    //export as pdf
    var url_ext = 'export?exportFormat=pdf&amp;format=pdf'   
        + (thisSheetId ? ('&amp;gid=' + thisSheetId) : ('&amp;id=' + theSpreadsheetId)) 
        // following parameters are optional...
        + '&amp;size=A4'      // paper size
        + '&amp;scale=2' // 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
        + '&amp;portrait=true'    // orientation, false for landscape
        + '&amp;horizontal_alignment=CENTER'  //LEFT/CENTER/RIGHT
        + '&amp;fitw=true'        // fit to width, false for actual size
        + '&amp;sheetnames=false&amp;printtitle=false&amp;pagenumbers=false'  //hide optional headers and footers
        + '&amp;gridlines=true'  // hide gridlines
        + '&amp;printnotes=false' // don't show notes
        + '&amp;fzr=true';       // repeat row headers (frozen rows) on each page
    // Setup options
    var options = 
    {
      headers: 
      {
        'Authorization': 'Bearer ' +  ScriptApp.getOAuthToken(),
      }
    }
    // Build the file
    var response = UrlFetchApp.fetch(url_base + url_ext, options);
    var blob = response.getBlob().setName(theOutFileName);
    var folder = DriveApp.getFolderById(&quot;ABC123FooBarID&quot;);
    var newFile = DriveApp.createFile(blob); //Create a new file from the blob
    newFile.setName(InboundID + &quot;.pdf&quot;); //Set the file name of the new file
    newFile.makeCopy(folder);
  }
  </code></pre>