Skip to main content
Inspiring
October 17, 2020
Answered

Convert page numbers to text

  • October 17, 2020
  • 2 replies
  • 1289 views

Hi, does exist any script to convert page number (~N) inserted to text to simply text? I mean remove it and paste the number to this place.
Thank you... Ilja

This topic has been closed for replies.
Correct answer Sunil Yadav

Try this code snippet:

main();
function main(){
    app.findGrepPreferences = null;
    app.changeGrepPreferences = null;
    app.findChangeGrepOptions.includeMasterPages = true;
    app.findGrepPreferences.findWhat="~N";
    var FindGrep=app.activeDocument.findGrep();
    for(i=0; i<FindGrep.length; i++){
        var item = FindGrep;
        var page = item.parentTextFrames[0].parentPage;
        if(page != null){
            item.contents = page.name;
            }
        }
    app.findGrepPreferences = null;
    app.changeGrepPreferences = null;
    }  

Best

Sunil

2 replies

Sunil Yadav
Sunil YadavCorrect answer
Legend
October 17, 2020

Try this code snippet:

main();
function main(){
    app.findGrepPreferences = null;
    app.changeGrepPreferences = null;
    app.findChangeGrepOptions.includeMasterPages = true;
    app.findGrepPreferences.findWhat="~N";
    var FindGrep=app.activeDocument.findGrep();
    for(i=0; i<FindGrep.length; i++){
        var item = FindGrep;
        var page = item.parentTextFrames[0].parentPage;
        if(page != null){
            item.contents = page.name;
            }
        }
    app.findGrepPreferences = null;
    app.changeGrepPreferences = null;
    }  

Best

Sunil

Community Expert
October 17, 2020