How to get first page document Indesign

Community Beginner ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

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?

TOPICS
How to , Scripting

Views

116

Likes

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 16, 2021 Dec 16, 2021

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

Likes

Translate

Translate
Advocate ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

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

Likes

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 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

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!

Likes

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
Adobe Community Professional ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

Hi @mikeb41294032,

Why the loop? Won't the following work

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

-Manan

Likes

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 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

@Manan Joshi,

 

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

 

Regards,

Mike

Likes

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
Adobe Community Professional ,
Dec 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

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

Likes

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 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

Fantastic, a quick fix. Is there a way to enter the result into a textbox? Thank you very much for the solution.

Likes

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 16, 2021 Dec 16, 2021

Copy link to clipboard

Copied

LATEST

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

Likes

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