Skip to main content
priyak7746321
Inspiring
April 11, 2019
Answered

didn't get Last page

  • April 11, 2019
  • 1 reply
  • 1027 views

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.

This topic has been closed for replies.
Correct answer Laubender

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

1 reply

priyak7746321
Inspiring
April 11, 2019

Any idea. Your's suggestions should be appreciated.

LaubenderCorrect answer
Brainiac
April 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

priyak7746321
Inspiring
April 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