Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
Any idea. Your's suggestions should be appreciated. ![]()
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you so much. It's working fine.
Please explain the functionality pages[-1].getElements()[0] and why pages.lastItem(); its not working
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now