问题
What is the DOM expression to get current page where the cursor is:
app.activeDocument.currentPage ?
回答1:
You want:
app.activeWindow.activePage.name;
This will give you the actual page number name as a string (i.e. if your pages are numbered in roman then this will give 'v' for the fifth page).
回答2:
The below would create a Text Block with the current page number. You could also have this be applied to the master page by changing the page location for which the text frame is placed.
myDocument = app.activeDocument;
var myDocument = app.documents.item(0);
var myPage = myDocument.pages.item(0);
var myTextFrame = myPage.textFrames.add();
//Set the bounds of the text frame.
//
myTextFrame.geometricBounds = [0, 0, .52, 5.5];
//Enter text in the text frame.
//("\r" is a return character.+
myTextFrame.contents = "P_";
myTextFrame.parentStory.insertionPoints.item(-1).contents = SpecialCharacters.autoPageNumber;
来源:https://stackoverflow.com/questions/3770411/get-current-page-number-in-indesign-cs5-from-javascript