Skip to main content
Participant
December 2, 2023
Question

Need help with javascript command

  • December 2, 2023
  • 1 reply
  • 1142 views

I have a file of groups of 6 pages (3167 groups of 6, 19002 pages) where I need to delete 3rd,4th 5th and 6th page, then the 9th,10th,11th and 12th, and so forth, but retain the balance of the document.

How do I do this with an Action Tool Javascript?

This topic has been closed for replies.

1 reply

bebarth
Community Expert
Community Expert
December 2, 2023

Hi,

This simple script can be executed with an action wizard or from the console window:

for (var i=this.numPages-6; i>=0; i-=6) {
	this.deletePages({nStart: i+2, nEnd: i+5});
}
this.saveAs(this.path.replace(/.pdf$/i," \(2 pages kept every 6 pages\).pdf"));

The script save the new file with a new name in the same folder as the original one.

But with the number of pages, I suggest to display the progess of the process with this one:

console.show();
console.clear();
d0=new Date();
debut=util.printd("dd-mm HH:MM",d0);
laDate=util.printd("dd-mm-yy",d0);
var nb=0;
for (var i=this.numPages-6; i>=0; i-=6) {
	console.clear();
	console.println("Process Starting: "+debut);
	console.println("––––––––––––––");
	console.println("Removing group #"+(nb+1)+" from page #"+(i+1));
	this.deletePages({nStart: i+2, nEnd: i+5});
	nb++;
}
this.saveAs(this.path.replace(/.pdf$/i," \(2 pages kept every 6 pages\).pdf"));
df=new Date();
fin=util.printd("dd-mm HH:MM",df);
temps=(df.valueOf()-d0.valueOf())/1000/60;
var lesMinutes=parseInt(temps);
var lesSecondes=(temps-lesMinutes)*60;
var lesSecondes=parseInt(lesSecondes*10)/10;
var leTemps="";
if (lesMinutes>0) {
	if (lesMinutes==1) {
		var leTemps="1 minute";
	} else {
		var leTemps=lesMinutes+" minutes";
	}
}
if (lesSecondes>0) {
	if (lesSecondes<2) {
		var leTemps=leTemps+" "+lesSecondes+" second"
	} else {
		var leTemps=leTemps+" "+lesSecondes+" seconds"
	}
}
var leTemps=leTemps.replace(/^\s+|\s+$/gm,"");
console.clear();
console.println("Process Starting: "+debut);
console.println("Process Ending: "+fin);
console.println("––––––––––––––");
console.println("Process Duration: "+leTemps);
console.println(nb+" groups removed.");
console.println("Final file with "+this.numPages+" pages.");

 @+

Participant
December 4, 2023

Hi bebarth,

 

Thanks for writing that script for me. When I run it in javascript it crashes the file. Any ideas on why that happens?

bebarth
Community Expert
Community Expert
December 4, 2023

I don't have a huge file as yours...

Do a test with a 24-page file for example then if that works without crashing with a 300-page file!

Does that work?

Is the process displayed in the console window ?

@+