Page 1 of 1

Iterating through documents in job using scriptexpression

Posted: Tue Mar 11, 2014 10:56 am
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

Iterating through documents in job using scriptexpression

Posted: Tue Mar 11, 2014 1:31 pm
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

Iterating through documents in job using scriptexpression

Posted: Tue Mar 11, 2014 2:41 pm
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;

Iterating through documents in job using scriptexpression

Posted: Wed Mar 12, 2014 9:17 am
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!

Iterating through documents in job using scriptexpression

Posted: Wed Mar 12, 2014 1:17 pm
by menglv
Looks as if it is unable to work.

Iterating through documents in job using scriptexpression

Posted: Wed Mar 12, 2014 2:24 pm
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?

Iterating through documents in job using scriptexpression

Posted: Wed Mar 12, 2014 2:56 pm
by dkelly

Iterating through documents in job using scriptexpression

Posted: Fri Mar 14, 2014 10:40 am
by richardvicarykp
Many thanks for your help on this. It has worked a treat.