title: Google Apps Script Header/Footer Clear and Replace
body: <p>I have a script that updates Google Docs' header and footer (by retrieving parameters from the AODocs add-on) when a new document version is published.</p>
  
  <p>My problem is that the footer.clear() method doesn't seem to erase the header (or footer) and leaves a carriage return at the top of the section.  Subsequent versions keep "growing" in the footer space.</p>
  
  <p>Is this a known issue?  Am I doing it wrong? (I pull in a line from a template so that I can have pagination, too.</p>
  
  <p>Here's a code-snippet for the footer portion:</p>
  
  <pre><code>var footerTemplate = headerFooterTemplateDoc.getFooter();
  var footerParagraphs = footerTemplate.getParagraphs();
  
  // Bring in Parameters
  var title = request.parameter.title;
  var owner = request.parameter.owner;
  var revDate = request.parameter.revDate;
  var version = request.parameter.version;
  var driveFileID = request.parameter.driveFileID;   
  
  if (!DocumentApp.openById(driveFileID).getFooter()) {
   var footer = DocumentApp.openById(driveFileID).addFooter();
   } else {
   var footer = DocumentApp.openById(driveFileID).getFooter();
   footer.clear();
   }
  
  //Write the values
  footer.clear();
  footer.appendHorizontalRule();
  footer.appendParagraph(footerParagraphs[0].copy());
  footer.appendParagraph('Title: ' + title + ' - Owner: ' + owner);
  footer.appendParagraph('Version: ' + version + ' - Last Revised: ' + revDate).setSpacingAfter(18);
  </code></pre>