David Rowthorn February 2016

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);
   }
 }

Answers


Henrique Abreu February 2016

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).

Post Status

Asked in February 2016
Viewed 2,312 times
Voted 11
Answered 1 times

Search




Leave an answer