Tom Cruise
Tom Cruise

Reputation: 21

Adding dynamic header/footer to Docs

I'm wondering if there is a way to add dynamic headers or footers to a document, i.e. putting a "Page Title" in the footer that is different for every page.

I understand that editing the built-in header or footer would be reflected on every page. I'm wondering if anyone has thought of a workaround to either "force" it by accessing the first/last line on a page and inserting text there, or if there is another way to dynamically update the page.

Upvotes: 2

Views: 2525

Answers (1)

Mr.Rebot
Mr.Rebot

Reputation: 6791

AFAIK, this is not yet available. There is an open issue on can't reliably access first page vs other pages header / footer info.

I've used the codes here, to list the document's children.

DocumentBodySection: Index 0
HeaderSection: Index 1
FooterSection: Index 2
HeaderSection: Index 3
FooterSection: Index 4

This function change the text of the selected child.

function myFunction() {
  var copyDoc = DocumentApp.getActiveDocument();
  var footer = copyDoc.getFooter();
  Logger.log(footer.getParent().getChild(2).asText().setText("Test"))
}

Second Page enter image description here

Third Page enter image description here

Changing a footer section will apply to all footer section, according to this blog you can only set a different header/footer in the first page. The provided open issue link also states that it can only be checked manually as it is not available.

Upvotes: 1

Related Questions