Skip to main content
Inspiring
October 27, 2023
Answered

How to remove each Footnote textframes in a page using indesign javascript

  • October 27, 2023
  • 2 replies
  • 785 views

Hi I am trying to select and remove all footnote textframes in all pages of a document

This topic has been closed for replies.
Correct answer FRIdNGE
app.activeDocument.stories.everyItem().footnotes.everyItem().remove();

 

(^/)  The Jedi

2 replies

Robert at ID-Tasker
Legend
October 27, 2023

You can't delete footnote's TextFrame - footnote shares TextFrame of the text where the reference is - you need to delete reference in the text. 

 

FRIdNGE
FRIdNGECorrect answer
October 27, 2023
app.activeDocument.stories.everyItem().footnotes.everyItem().remove();

 

(^/)  The Jedi

Community Expert
October 27, 2023

Every textframe has a footnotes property. You can iterate on the textframes collection and check the footnotes length, if it is greater that 0 you can delete the textframe.

Something like

if(tf.footnotes.length) //delete the textframe

-Manan

-Manan
Inspiring
October 27, 2023

I tried it but the footnotes length

var doc = app.activeDocument;
var pagess = doc.pages;

for(var p=0; p<pagess.length; p++){
    var pgTxtFrames = pagess[40].textFrames;
    for(var t=0; t<pgTxtFrames.length; t++){
       // pgTxtFrames[t].remove();
        if(pgTxtFrames[t].footnotes.length >0){ 
            for(var f=0; f<pgTxtFrames[t].footnotes.length; f++){
             pgTxtFrames[t].footnotes[0].parentTextFrames[0].remove();
             }
         }
        }
    }


   

was Zero  but footnotes were present in each page

Robert at ID-Tasker
Legend
October 27, 2023

This line is your problem:

 

var pgTxtFrames = pagess[40].textFrames; 

 

You are referring to a 40th page all the time - it should be "p" instead - [p].