New job from existing file
Posted: Mon Apr 03, 2017 2:08 pm
Hi
I am trying to get the total page count of all files in a zip file and without using external scripts only way I know of is to use job.getVariableAsNumber("[Stats.NumberOfPages]"), but that requires that the files are turned into jobs, doesn't it? I tried to implement that idea, but I can't figure out how I can create a job from an existing file.
I tried creating a new job and copying the existing file into a path defined to it, but still I can't get the Stats.NumberOfPages out from the file, Switch only says "The requested statistics are not available for the job 'C:/Users/Switchuser/AppData/Roaming/Enfocus/Switch Server/temp/EnvironmentClass/2145/_0A1OR_dummyFileForNewJob.dat': the job does not exist" --> how can I get the statistics out from the pdf files through the job? Or am I trying a too complicated way to solve this?
Here is (one example of) what I've tried:
Any help is much appreciated,
Patrik
I am trying to get the total page count of all files in a zip file and without using external scripts only way I know of is to use job.getVariableAsNumber("[Stats.NumberOfPages]"), but that requires that the files are turned into jobs, doesn't it? I tried to implement that idea, but I can't figure out how I can create a job from an existing file.
I tried creating a new job and copying the existing file into a path defined to it, but still I can't get the Stats.NumberOfPages out from the file, Switch only says "The requested statistics are not available for the job 'C:/Users/Switchuser/AppData/Roaming/Enfocus/Switch Server/temp/EnvironmentClass/2145/_0A1OR_dummyFileForNewJob.dat': the job does not exist" --> how can I get the statistics out from the pdf files through the job? Or am I trying a too complicated way to solve this?
Here is (one example of) what I've tried:
Code: Select all
var file = job.getPath();
var unzipPath = job.createPathWithName( "unzipped", true );
var pageCount = 0;
if( !s.unarchive( file, unzipPath ) ){
job.fail( "Failed to unarchive "+file );
return;
}
else {
var pdfDir = new Dir(unzipPath);
var pdfFiles = pdfDir.entryList("*.pdf", Dir.Files, Dir.Name);
for(var f=0;f<pdfFiles.length;f++){
var tempJob = s.createNewJob();
var filePath = tempJob.createPathWithName('pdfFile.pdf',false);
s.copy(unzipPath+'/'+pdfFiles[f],filePath);
pageCount += tempJob.getVariableAsNumber("[Stats.NumberOfPages]"); //this results in the error mentioned above
}
s.log(2,'page count:'+pageCount);
}
Patrik