Iterating through documents in job using scriptexpression

Post Reply
richardvicarykp
Newbie
Posts: 3
Joined: Tue Mar 11, 2014 10:45 am

Iterating through documents in job using scriptexpression

Post by richardvicarykp »

Hi,



I have some inbound documents that come in and are of unknown number of pages. I want to group them into a single job and then add blank pages to each file such that all documents end up with the same number of pages as the longest document in the job. Can someone tell me the javascript syntax to achieve:



var largestbook = 0

var currentbook = 0

For each document in job

currentbook = document.noofpages

if currentbook > largestbook then

largestbook = currentbook

end if

next document



Very grateful for your time.



Richard
freddyp
Advanced member
Posts: 1024
Joined: Thu Feb 09, 2012 3:53 pm

Iterating through documents in job using scriptexpression

Post by freddyp »

I suggest that you use "Rename job" to add the page count to the PDF file name before you assemble them into a folder. Then you can use this script expression to find the highest page count.



var inputFolder = new Dir(job.getPath());

var filesInFolder = inputFolder.entryList("*.pdf", Dir.Files, Dir.Name);

var largestbook = 0;

var currentbook = 0;

var re = /d*$/;

for (var i=0; i largestbook) {

largestbook = currentbook

}

}

largestbook;



If you do not want to do the rename you will have to use a script element rather than a script expression, because you will have to create jobs of the PDF's in the job folder in order to access the Stats variables, and this is not something you can do in a script expression.



Freddy
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Iterating through documents in job using scriptexpression

Post by dkelly »

var inputFolder = new Dir(job.getPath());

var filesInFolder = inputFolder.entryList("*.pdf", Dir.Files, Dir.Name);

var largestbook = 0;

var currentbook = 0;

var re = /d*$/;

for (var i=0; i<filesInFolder.length; i++) {

var curFileStats = new FileStatistics(job.getPath()+"/"+filesInFolder);

currentbook = curFileStats.getNumber("NumberOfPages");

if (currentbook > largestbook) {

largestbook = currentbook

}

}

largestbook;
freddyp
Advanced member
Posts: 1024
Joined: Thu Feb 09, 2012 3:53 pm

Iterating through documents in job using scriptexpression

Post by freddyp »

This shows that you are never done browsing through the extensive scripting documentation. I did not know about the Filestatistics class :).



Thank you Dwight!
menglv
Newbie
Posts: 15
Joined: Mon Mar 10, 2014 10:25 am

Iterating through documents in job using scriptexpression

Post by menglv »

Looks as if it is unable to work.
richardvicarykp
Newbie
Posts: 3
Joined: Tue Mar 11, 2014 10:45 am

Iterating through documents in job using scriptexpression

Post by richardvicarykp »

Many thanks for your suggestions, I will be trying them out later this week. I'm not sure that I have the scripting documentation, does it ship with Switch?
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Iterating through documents in job using scriptexpression

Post by dkelly »

richardvicarykp
Newbie
Posts: 3
Joined: Tue Mar 11, 2014 10:45 am

Iterating through documents in job using scriptexpression

Post by richardvicarykp »

Many thanks for your help on this. It has worked a treat.
Post Reply