Skip to main content
Participant
December 14, 2019
Answered

Javascript Inverted page number

  • December 14, 2019
  • 4 replies
  • 3121 views

Any idea to write a javascript for InDesign that insert inverted page number on any page based on document

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

Try this code:

 

var c = 0;
while(c < app.activeDocument.pages.length){
    try{
       var sec = app.activeDocument.sections.add(app.activeDocument.pages[c]);
       sec.continueNumbering = false;
       sec.pageNumberStart = app.activeDocument.pages.length-c;
        }
   catch(e){
       var sec = app.activeDocument.pages[c].appliedSection;
       sec.continueNumbering = false;
       sec.pageNumberStart = app.activeDocument.pages.length-c;
       }
    c++;
    }

 

Best

Sunil

4 replies

M.Hasanin
Inspiring
June 11, 2020

Wow, Great Job Sunail, Can i ask what if i want to Invert Pages as Well with the Inverted Numbers so Everyting will be Logic? Can this be done ?

Best Regards

Mohammad Hasanin

Mohammad Hasanin
Sunil Yadav
Legend
June 13, 2020
M.Hasanin
Inspiring
June 14, 2020

yes, thank you very much

Mohammad Hasanin
brian_p_dts
Community Expert
Community Expert
December 14, 2019

The actual page number is accessible via "page.name". I haven't drunk sufficient coffee to figure out an invert mechanism, but parse the name as an int then doing some kind of calc on the total # of pages would probably work. You would take the new figure and reinsert into page.name.

var pages = app.activeDocument.pages;
for (var i = 0; i < pages.length; i++) {
$.writeln(pages[i].name);
}
rob day
Community Expert
Community Expert
December 14, 2019

The actual page number is accessible via "page.name".

 

The page name string could be a letter—if the page was a section start using roman numerals, page one of the section would be named "i". There's also page.documentOffset which reurns the page’s sequential number relative to the document.

 

If an auto Current Page Number is being used it might be possible to set every page to a section start and reverse the order of the auto page numbering. I can’t do it easily in JS, but this AppleScript (OSX only) seems to work.

 

 

 

 

tell application "Adobe InDesign CC 2018"
	tell active document
		set allow page shuffle of document preferences to false
		my clearSections()
		set p to every page
		set c to count of p
		repeat with i from 1 to c
			set pn to c - (i - 1)
			set itm to item i of p
			try
				make new section with properties {continue numbering:false, page start:itm, page number start:pn}
			end try
		end repeat
	end tell
end tell

--reset the sections
on clearSections()
	tell application "Adobe InDesign CC 2018"
		tell active document
			set s to every section
			repeat with i from 2 to count of s
				try
					delete item i of s
				end try
			end repeat
		end tell
	end tell
end clearSections

 

 

 

 

olafaAuthor
Participant
December 14, 2019

Wonderful.

The result is exacly what I was waiting for.

If the document get new pages, re-run the script.

Thank you. 

rob day
Community Expert
Community Expert
December 14, 2019

You could reverse the page order via scripting, but if the page numbers are a special character like Current Page Number the page numbers would get updated and changed as you move the pages. Your page numbers would have to be regular numbers.

Community Expert
December 14, 2019

What do you mean by inverted page number. How do you do it manually, is it just about entering the page number in a frame and then flipping the frame?

 

-Manan

-Manan
olafaAuthor
Participant
December 14, 2019

NO,

The purpose is :the first logic page number of the document become the last number.

Example a 10 pages document :

the first logic page is 10

the last logic page is 1

Olivier

Jongware
Community Expert
Community Expert
December 15, 2019

Set the binding type to Right-to-Left.