Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Javascript Inverted page number

Community Beginner ,
Dec 14, 2019 Dec 14, 2019

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

TOPICS
How to , Scripting
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Dec 29, 2019 Dec 29, 2019

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

Translate
Community Expert ,
Dec 14, 2019 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2019 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2019 Dec 15, 2019

Set the binding type to Right-to-Left.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 29, 2019 Dec 29, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2019 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2019 Dec 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);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2019 Dec 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

 

 

 

 

Screen Shot 6.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2019 Dec 14, 2019

Wonderful.

The result is exacly what I was waiting for.

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

Thank you. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2019 Dec 14, 2019

مجموعة الأدوات منصة        [10] شليلة 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 11, 2020 Jun 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

Best
Mohammad Hasanin
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 13, 2020 Jun 13, 2020
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 14, 2020 Jun 14, 2020
LATEST

yes, thank you very much

Best
Mohammad Hasanin
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines