Skip to main content
Inspiring
August 16, 2013
Question

How can i apply a CharStyle for created footnote on the fly? [CS6-jsx]

  • August 16, 2013
  • 1 reply
  • 1163 views

I insert footnote insted of founded text.

mSn_text = mFound.contents; //get footnote's content

mFound.contents=""; //clear contents for keeping number of future footnote

var myFootnote = mFound.footnotes.add();

myFootnote.insertionPoints[-1].contents = mSn_text;

myFootnote.words[0].position = Position.SUPERSCRIPT;

       

mFound.appliedCharacterStyle = aD.characterStyles.item(mName);

And would like to mark footnote's numbers in text by red color (for clear view). How can i apply characterStyle or just color for footnote number in text (on the fly)? )

This topic has been closed for replies.

1 reply

Community Expert
August 16, 2013

@Dmitry – just like in the UI.

You can control the footnote with the footnote options like that:

app.documents[0].footnoteOptions.footnoteMarkerStyle = "myCharacterStyle";

Uwe

Vamitul
Legend
August 16, 2013

also you are overcomplicating things a bit by first storing the footnote text in a temp variable, removing the content of the found text (error proned, might invalidate the insertion point reference).

here is a function from a larger script of mine (also handles somewhat footnotes in tables):

  function dofn(sel) {

    var pare = sel.parent.getElements()[0];

    var ip = sel.insertionPoints[0].index;

    //Special case for fn in tabel

    if (pare instanceof Cell) {

      var fake = pare.texts[0].insertionPoints[ip].contents = (app.activeDocument.footnoteOptions.showPrefixSuffix == FootnotePrefixSuffix.PREFIX_SUFFIX_BOTH || app.activeDocument.footnoteOptions.showPrefixSuffix == FootnotePrefixSuffix.PREFIX_SUFFIX_REFERENCE) ? app.activeDocument.footnoteOptions.prefix + 'XX' + app.activeDocument.footnoteOptions.suffix : 'NN';

      pare.insertionPoints.itemByRange(ip, ip + fake.length).getElements()[0].appliedCharacterStyle = app.activeDocument.footnoteOptions.footnoteMarkerStyle;

      ip = pare.parentRow.parent.storyOffset.index + 1;

      pare = sel.parentStory;

   //   errors.push("Footnote found in table; Reference moved at the end of table");

    }

    var fn = pare.footnotes.add(LocationOptions.BEFORE, pare.insertionPoints[ip]);

    sel.move(LocationOptions.BEFORE, fn.texts[0].insertionPoints[-1]);

    fn.texts.everyItem().applyParagraphStyle(app.activeDocument.footnoteOptions.footnoteTextStyle)

    return fn

  }

BeliakovAuthor
Inspiring
August 16, 2013

Yes. After some thinking i got idea and change my lines with your way. All does work))