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

Problem in fetching last page number.

New Here ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

Hi all my name is Avi. I am new to this forum. I have some problem regarding javascript. How to fetch last page number.

I created a Text field using javascript which is as follows

var myTextFrame4 = myDocument.pages.item(0).textFrames.add();
myTextFrame4.geometricBounds = ["38p6", "21p0", "39p3", "30p0"];
myTextFrame4.contents = "5Page ";
myTextFrame4.parentStory.insertionPoints.item(-1).contents = SpecialCharacters.autoPageNumber;
myTextFrame4.parentStory.insertionPoints.item(-1).contents = " of ??6";

In above code i am using autopagenumbering. My problem is i want to fetch last page number and change ?? to that page number.
For Example i am inserting text in document and 5 page will be generated by using autoPageNumber the text field will chage to page 1 of ?? .....
and at last page 5 of ??. What i want to change the ?? to 5(which is last page when you insert te text). I want replace the ?? to last page number.

There is one page properties which is length which gives you how many number of pages in the collection but i am not able to use it properly to get the expected output.

What kind of change i need to make in my script to get the expected output.
I knew this will be difficult to fetch last page number but i hope i will get my answer for this forum.

Thank you,

--Avi
TOPICS
Scripting

Views

855

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 ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

I'm not JS man but I'll try to help you

change line:
myTextFrame4.parentStory.insertionPoints.item(-1).contents = SpecialCharacters.autoPageNumber;

to

myTextFrame4.parentStory.insertionPoints.item(-1).contents = myTextFrame4.parent.name;

you need to check ".parent.name" - JS is CaseSensitive


and description from VB ObjectBrowser:

Property Parent As Variant
read-only
Member of InDesign.TextFrame
The TextFrame's parent as Spread, MasterSpread, PageItem, Oval, Rectangle, Polygon, GraphicLine, Group, State, Document, Layer, Page, Button, TextFrame, Story, Text, Character, Word, Line, TextColumn, Paragraph, TextStyleRange, Cell, Table, InsertionPoint or Footnote

you should find same info in ESTK ...

robin

--
www.adobescripts.com

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
New Here ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

How can this help me to change ?? to page number.

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 ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

oh sorry,

change line:
myTextFrame4.parentStory.insertionPoints.item(-1).contents = " of ??6";

to:

myTextFrame4.parentStory.insertionPoints.item(-1).contents = " of ";
myTextFrame4.parentStory.insertionPoints.item(-1).contents = app.activeDocument.pages.item(-1).name;

ignore my earlier post

robin

--
www.adobescripts.com

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
Contributor ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

Avi,

in CS3 you may make a new text variable with type of last page number with document scope:

<pre>
d = app.activeDocument;
v = d.textVariables.add( {name:'Last Page', variableType:VariableTypes.LAST_PAGE_NUMBER_TYPE} );
v.variableOptions.scope = VariableScopes.DOCUMENT_SCOPE;
</pre>

Now you will have to insert the text variable at your insertion point.

But how to insert a text variable?

"myInsertionPoint.contents = v;" will not work.

Martin Fischer

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
Contributor ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

Avi,

you can add a text variable to an insertion point like this (given myInsertionPoint and myTextVariable):

> myInsertionPoint.textVariableInstances.add( {associatedTextVariable : myTextVariable} );

Martin Fischer

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
New Here ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

Hello Robin

Thank you for your post but the problem is when i am trying to entered the text then it will create 11 page .But still it showing text field page 1 of 1 and for the next page page 2 of 1 ...... at last page 11 of 1. But this is not the output i want.

I want page 1 of 11 and for next page 2 of 11.......at last page 11 of 11.

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 ,
Feb 04, 2008 Feb 04, 2008

Copy link to clipboard

Copied

can you place again this part of your script ??

robin

--
www.adobescripts.com

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 ,
Feb 04, 2008 Feb 04, 2008

Copy link to clipboard

Copied

Avi,

>There is one page properties which is length which gives you how many number of pages in the collection but i am not able to use it properly to get the expected output.

myDocument.pages.length

should give you the number of pages in the document. Why does that not work for you?

Alternatively, if you're using CS3 you could use MArtin's suggestion.

Peter

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
New Here ,
Feb 04, 2008 Feb 04, 2008

Copy link to clipboard

Copied

var myTextFrame4 = myDocument.pages.item(0).textFrames.add();
myTextFrame4.geometricBounds = ["38p6", "21p0", "39p3", "30p0"];
myTextFrame4.contents = "5Page ";
myTextFrame4.parentStory.insertionPoints.item(-1).contents = SpecialCharacters.autoPageNumber;
//myTextFrame4.parentStory.insertionPoints.item(-1).contents = " of ??6";
myTextFrame4.parentStory.insertionPoints.item(-1).contents = " of ";
myTextFrame4.parentStory.insertionPoints.item(-1).contents = app.activeDocument.pages.item(-1).name;
myTextFrame4.parentStory.insertionPoints.item(-1).contents = " 6";

This the script which i am using but still i am not getting correct output. What i want is to when i entred the text using shift + ctrl (MAC OS X) on that page it will generate suppose 10 page then i need to change ?? to 10(Number of pages generated)

I tried all the suggestion given by this forum but not a single one is working fine for me.

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 ,
Feb 04, 2008 Feb 04, 2008

Copy link to clipboard

Copied

remove last line and should be ok

robin

--
www.adobescripts.com

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
New Here ,
Feb 04, 2008 Feb 04, 2008

Copy link to clipboard

Copied

When you remove that line it sill showing a square box.
I want to change a the number of page when you close the program.

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 ,
Feb 13, 2008 Feb 13, 2008

Copy link to clipboard

Copied

Avi:

I use this script every day for the task you are describing.
I set a keyboard shortcut to call the script so I can update it frequently as needed.

Follow these steps:

1. Type out the words "Page 1 of X"

2. Add a new character style to your document named "LastPageNumber" and apply the character style to just that character "X". NOTHING ELSE!

3. Run the script from the scripts panel or set a keyboard shortcut to run the script.

The last page number will update after you run the script.

Copy and paste this code into a jsx file and save it in your scripts folder.

var myDoc = app.activeDocument;
var myPageCount = myDoc.pages.length + "";

var myStyle = myDoc.characterStyles.item("LastPageNumber");
app.findPreferences = app.changePreferences = null;

myDoc.search("",false,false,myPageCount,{appliedCharacterStyle:myStyle});

app.findPreferences = app.changePreferences = null;

Good Luck!

TJV

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
New Here ,
Feb 14, 2008 Feb 14, 2008

Copy link to clipboard

Copied

LATEST
Thank you.
This is the perfect ans what i am looking for.
Can you give me your email id. So, if i have any doubt i can contact directly.

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