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

didn't get Last page

Participant ,
Apr 11, 2019 Apr 11, 2019

In my document has footnotes and texts.  While doing the auto pagination I tired to align the last page via script

But the last page has only five lines. When I try to get he last page the script return the previous page. (Issue only in script running  time)

I tried like below even though its not returning the correct page.

        doc.preflightOptions.preflightOff = false;

        doc.activeProcess.waitForProcess(120);

        doc.preflightOptions.preflightOff = true;

            var pages=doc.pages;

            var lastpage=pages.lastItem();

How do I resolve the issue.

TOPICS
Scripting
1.0K
Translate
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

Community Expert , Apr 11, 2019 Apr 11, 2019

Hi, priyak7746321 ,

maybe the collection of pages you assigned variable pages to is not updated in the moment you want to access the last page in the document?

When you try to access the last page in the document try to resolve the last page like this:

var lastPage = app.documents[0].pages[-1].getElements()[0];

Or you could enforce a total redraw of the document and then access the last page through its collection.

( function()

{

   

    if( app.documents.length == 0 ){ return };

   

    // FWIW: Item b

...
Translate
Participant ,
Apr 11, 2019 Apr 11, 2019

Any idea. Your's suggestions should be appreciated.

Translate
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 ,
Apr 11, 2019 Apr 11, 2019

Hi, priyak7746321 ,

maybe the collection of pages you assigned variable pages to is not updated in the moment you want to access the last page in the document?

When you try to access the last page in the document try to resolve the last page like this:

var lastPage = app.documents[0].pages[-1].getElements()[0];

Or you could enforce a total redraw of the document and then access the last page through its collection.

( function()

{

   

    if( app.documents.length == 0 ){ return };

   

    // FWIW: Item by name will not work for "force redraw":

    var forceRedraw = app.scriptMenuActions.itemByID(318);

    if( forceRedraw.isValid ){ forceRedraw.invoke() }

   

}() )

Regards,
Uwe

Translate
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
Participant ,
Apr 11, 2019 Apr 11, 2019

Thank you so much. It's working fine.

Please explain the functionality pages[-1].getElements()[0] and why pages.lastItem(); its not working

Translate
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 ,
Apr 11, 2019 Apr 11, 2019
LATEST

I can only guess why pages.lastItem() will not work as expected in your code.

From your report I understand that you'll get exactly the page, that was the last page, before InDesign was adding a page automatically.

With getElements() you enforce InDesign to drill through to the object(s) you are addressing with that collection.

It will create an array. Since we are addressing a single item the array will contain only one item. We get that with getElements()[0] .

pages[-1] will address the last item in the collection of pages.

So pages.lastItem().getElements()[0] should work as well.

Regards,
Uwe

Translate
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