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

Javascript Inverted page number

Community Beginner ,
Dec 14, 2019 Dec 14, 2019

Copy link to clipboard

Copied

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

TOPICS
How to , Scripting

Views

2.2K

Translate

Translate

Report

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

Votes

Translate

Translate
Community Expert ,
Dec 14, 2019 Dec 14, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Set the binding type to Right-to-Left.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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);
}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Wonderful.

The result is exacly what I was waiting for.

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

Thank you. 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

yes, thank you very much

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

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