title: Exporting Google Sheet as PDF with Custom Headers or Footers in Google Apps Script
body: <p>I'm wondering how to add custom headers or footers to a PDF that is exported using Google Apps Script from a Google Sheet. I would like to add a footer that says &quot;My Company Proprietary and Confidential&quot; in the center of the page.</p>
  <p>This is functionality that is available in normal PDF export from Sheets (i.e. File » Download as » PDF » Headers &amp; footers » EDIT CUSTOM FIELDS), but I don't know how to replicate it with URL parameters. I've also tried setting <code>'&amp;sheetnames=true&amp;printtitle=true'</code>, but this puts the sheet name and spreadsheet name in the header instead of the footer.</p>
  <p>Are there any additional URL parameters I can use to control these custom fields?</p>
  <pre><code>  var url = 'https://docs.google.com/spreadsheets/d/'+sourceSpreadSheet.getId()
    +'/export?exportFormat=pdf&amp;format=pdf' // export as pdf / csv / xls / xlsx
    + '&amp;size=letter'                           // paper size legal / letter / A4
    + '&amp;portrait=false'                     // orientation, false for landscape
    + '&amp;fitw=true'                        // fit to page width, false for actual size
    + '&amp;sheetnames=false&amp;printtitle=false' // hide optional headers and footers
    + '&amp;pagenum=CENTER&amp;gridlines=false' // hide page numbers and gridlines
    + '&amp;fzr=false'                         // do not repeat row headers (frozen rows) on each page
    + '&amp;gid='+sourceSheet.getSheetId()    // the sheet's Id
    + '&amp;top_margin=0.45&amp;left_margin=0.25&amp;right_margin=0.25&amp;bottom_margin=0.5'; // margins
  </code></pre>
  <p>Target Footer:</p>
  <p><a href="https://i.stack.imgur.com/mS46a.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mS46a.jpg" alt="footer screenshot" /></a></p>