DavidR
DavidR

Reputation: 369

Google Script: interacting with footnotes

I'm (very) new to google script (and javascript) and I'm trying to write a script to modify the font size of the footnotes in my document. Unfortunately, there is very little guidance that I can find for interacting with footnotes in a document.

So far I have tried to work from this base, but I get the error

Cannot find function setAttributes in object function getFootnoteContents() {/* */}.

I'm not looking for a "solve this for me answer", just perhaps some pointer as to how to work with the contents of a footnote or somewhere to start the learning process in that direction.

My code is as follows:

function footSize() {
  var doc = DocumentApp.getActiveDocument();
  var footnotes = doc.getFootnotes();
  var style = {};
  style[DocumentApp.Attribute.FONT_SIZE] = 18;
  for(var i in footnotes ){
  Logger.log(footnotes[i].getFootnoteContents.setAttribute(style));
  }
}

SOLUTION using Henrique's answer:

function footSize() {
 var footnote = DocumentApp.getActiveDocument().getFootnotes();
 var style = {};
 style[DocumentApp.Attribute.FONT_SIZE] = 18;
 for(var i in footnote){
   footnote[i].getFootnoteContents().setAttributes(style);
   }
 }

Upvotes: 1

Views: 864

Answers (1)

Henrique G. Abreu
Henrique G. Abreu

Reputation: 17752

getFootnoteContent is a function that retrieves the footnote section so you can manipulate its contents. You could try setting this attribute in the contents (you missed the parenthesis to call the content function) or in the footnote itself.

footnotes[i].setAttribute(style); //or
footnotes[i].getFootnoteContents().setAttribute(style); //note the parenthesis

--to address you edit

After you edited this error would not popup. You're not even referencing getFootnoteContents anymore. If setting the style does not work in the footnote object itself, try setting in its section (2nd suggestion).

Upvotes: 1

Related Questions