Skip to main content
Participant
December 16, 2021
Answered

How to get first page document Indesign

  • December 16, 2021
  • 2 replies
  • 630 views

Hi, I would like to get the number of the first page of a document. Example: page 5-20, where number 5 is the first page of the document. I got the last page through a bookmark that Indesign itself makes available, but the first page I don't know how to do. Can someone help me?

This topic has been closed for replies.
Correct answer Mike Bro

Hello @PUC Goiás,

 

You can try this...

var curr_origin = app.activeDocument.viewPreferences.rulerOrigin;
app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

// the location and size for the textframe
var y1 = 0;
var x1 = 0;
var y2 = .125;
var x2 = .125;

var tf = app.documents[0].pages[0].name
app.documents[0].pages[0].textFrames.add({
contents: tf,
geometricBounds: [y1, x1, y2, x2]
});

 

Regards,

Mike

2 replies

Community Expert
December 16, 2021

Hi @Mike Bro,

Why the loop? Won't the following work

alert(app.documents[0].pages[0].name)

-Manan

-Manan
Legend
December 16, 2021

@Manan Joshi,

 

yes!....it was 5am here before I had any coffee....

 

Regards,

Mike

Community Expert
December 16, 2021

Totally getting you Mike. Infact I was also skeptical about it, I thought if you have written it there must be a reason to it. But then I convinced myself that even break has been used, so seems like something is not right.

You never know when it's a trick question to bowl you over 🙂

-Manan

-Manan
Legend
December 16, 2021

Hello @PUC Goiás,

 

try this....

doc = app.activeDocument;
for (var i=0; i<doc.pages.length; i ++) {
 var myFirstPage = app.activeDocument.pages[i].name;
 break; 
}
alert(myFirstPage)

 

Regards,

Mike

Participant
December 16, 2021

Both solutions work perfectly. However, I would like to be able to print the result on the screen, that is, insert this information in a text box. It will be possible? thanks for helping!