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

Need help with javascript command

Community Beginner ,
Dec 01, 2023 Dec 01, 2023

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?

TOPICS
JavaScript
762
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 ,
Dec 02, 2023 Dec 02, 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.");

 @+

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 Beginner ,
Dec 04, 2023 Dec 04, 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?

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 ,
Dec 04, 2023 Dec 04, 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 ?

@+

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 Beginner ,
Dec 04, 2023 Dec 04, 2023

Hi bebarth,

I

m green when it comes to running these scripts. Could you please walk me through the proper way torun your script step by step. I got it to work once but not how I actually made it work. I broke up the file in a 6000 record batch and somehow it worked on that one and I used the action wizard with a custom command. I can't get the next 6000 records to work for me and I'm not sure why.

Any help is much appreciated.

Ty

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 ,
Dec 04, 2023 Dec 04, 2023

if you try to quit Acrobat after each 6000-page file!

What is the size of your entire file?

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 Beginner ,
Dec 04, 2023 Dec 04, 2023

The file size is around 14MB's not big at all.

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 ,
Dec 04, 2023 Dec 04, 2023

Did you try to quit Acrobat after each 6000-page file?

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 Beginner ,
Dec 04, 2023 Dec 04, 2023

Yes, I actually did get it to work but had to break the 19002 records up into 3 files. It would crash when I tried to process the entire list. The script worked perfect thanks again for your help writing it for me. I did get the console to open and watched the progress as it processed but it didn't like a huge amount of records to process!

 

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 ,
Dec 04, 2023 Dec 04, 2023
LATEST

Definitely a memory problem with Acrobat.... I can't tell you!

@+

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