Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


[Script] Deleting pages in bulk from a big document painfully slow

Adobe Community Professional ,
May 30, 2021 May 30, 2021

Copy link to clipboard

Copied

Hi Folks,

The issue is simple if we try to delete lots of pages from a big document say 2000 pages long, the process is very slow. A simple code snippet like the following takes ages to complete. For my testing I used a blank document with 2000 pages, I am sure for a fully composed production document the time will be more

for (i=0; i<50; i++)
 app.documents[0].pages[i].remove();

 Here I am trying to delete the pages in sequence but a practical scenario would be deleting specific pages. This issue was reported in response to another query posted on the forum for which I posted a potential code snippet

https://community.adobe.com/t5/indesign/extracting-pages-as-a-separate-indesign-document/m-p/1202971...

I tried different things like

  • Reducing the undo stack entry by calling the deletion call from within doScript to have a single undo entry
  • Opening the document without a window
  • Try the move method to move all the pages to delete at the end and then maybe use pagePerDocument property to remove those pages. But the move method causes the same time issue

Any ideas on how to speed this up? If we try to delete these pages using the pages panel it deletes much quicker so this has something to do with the communication of DOM with the InDesign objects in my opinion. Any insights would be really helpful

-Manan

TOPICS
Scripting

Views

331

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 ,
May 30, 2021 May 30, 2021

Copy link to clipboard

Copied

I would be defining pages as their own variable with getElements and iterating backward if we are doing removal ie: 

var allPages = app.documents[0].pages.everyItem().getElements();

for (var i = 50; i >= 0; i--) {

   allPages[i].remove();

}

 

This limits DOM calls and prevents potential indexing errors. Have you tried those ideas?

 

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 ,
May 30, 2021 May 30, 2021

Copy link to clipboard

Copied

Yeah @brianp311 i tried these ideas but unfortunately its still the same.

-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
Adobe Community Professional ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

You're trying to remove the first page, which isn't possible. Does that have anything to do with it?

Another approach might be this:

app.documents[0].pages.itemByRange(1,-1).remove();

But I found that deleting pages manually in the Pages panel is slow in big documents as well.

P.

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 ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Hi @Peter Kahrel,

It's still the same. Deleting from the UI does take a bit of extra time but the script is taking minutes to do this operation with the computer fans getting cranked up as well.

-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
Adobe Community Professional ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Hi Manan,

the only way where you can make it instantly is when you have to remove pages at the end of a document.

Then you simply can assign a new value for pagesPerDocument in the documentPreferences.

var removeAtEnd = 10;
var doc = app.documents[0];
var numPages = doc.documentPreferences.pagesPerDocument;

var newPageLength = numPages - removeAtEnd ;

if( newPageLength > 0 )
{
	doc.documentPreferences.pagesPerDocument = 
	newPageLength ;
};

 

Using itemByRange() remains very slow.

Just tested this with an empty document with 2000 pages where I removed pages 1-10.

 

Regards,
Uwe Laubender

( ACP )

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 ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

Hi @Laubender,

I was also pinning my hopes on pagesPerDocument, for that I thought exactly like you and tried using the move method to bring all the deletion candidates at the end. But, in such a case the move method becomes the bottleneck. I think we can now conclude there is no faster method using the remove method. I thought of one alternative solution, could be a lot of work though.

  • Exporting an IDML, unzipping it then modifying the spread XML's. It should mainly be about removing the page nodes for the spread XML's and then packing the folder back to IDML

The other option is to go with a C++ plugin that should be pretty fast.

-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
Adobe Community Professional ,
May 31, 2021 May 31, 2021

Copy link to clipboard

Copied

LATEST

Is duplicate/remove equally slow? Not around a computer this weekend to test. 

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