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
-
- Newbie
- Posts: 3
- Joined: Tue Mar 11, 2014 10:45 am
Iterating through documents in job using scriptexpression
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
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
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Iterating through documents in job using scriptexpression
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;
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
This shows that you are never done browsing through the extensive scripting documentation. I did not know about the Filestatistics class
.
Thank you Dwight!

Thank you Dwight!
Iterating through documents in job using scriptexpression
Looks as if it is unable to work.
-
- Newbie
- Posts: 3
- Joined: Tue Mar 11, 2014 10:45 am
Iterating through documents in job using scriptexpression
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?
-
- Newbie
- Posts: 3
- Joined: Tue Mar 11, 2014 10:45 am
Iterating through documents in job using scriptexpression
Many thanks for your help on this. It has worked a treat.