Compare specific properties of two pdf files (beginner)

Post Reply
tkittel
Member
Posts: 50
Joined: Thu Jul 21, 2011 7:30 am

Compare specific properties of two pdf files (beginner)

Post by tkittel »

Hello,



I've a flow, where incoming folders always contain two pdf files (only). In the 1st step, 'ungroup job' splits the pdf files out of their folder. In the 2nd step the modification dates of both pdfs should be compared and the prefix "top_" should be added to the newer one. The 3rd step, should move both pdf files back into their original folder using the 'assemble job' element.



What's the best way to realize step 2 ?



Thanks for help!

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

Compare specific properties of two pdf files (beginner)

Post by dkelly »

Your comparison will have to occur before the Ungroup. The two files will be in separate jobs and can't be (easily) compared.
tkittel
Member
Posts: 50
Joined: Thu Jul 21, 2011 7:30 am

Compare specific properties of two pdf files (beginner)

Post by tkittel »

Hello Dwight,



thanks for your info - I was afraid that it will not be easy.



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

Compare specific properties of two pdf files (beginner)

Post by dkelly »

I was able to create a script that performs the function you requested. Create a Scripted element with a single property named "prefix". Set the property to "out_" when you add Script to your flow.





function jobArrived( s : Switch, job : Job )

{

if (job.isFile()) {

job.sendToSingle(job.getPath());

} else {

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

var theDirEntries = theJobDir.entryList("*.pdf", Dir.Files, Dir.Time);

var i;



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

var fileName = theJobDir.path + "/" + theDirEntries;

if (i==0) {

// rename the oldest file

var theFile = new File(fileName);

var theNewName = s.getPropertyValue("prefix", job) + theFile.name;

var outFilename = job.createPathWithName(theNewName, false);

s.copy(fileName, outFilename);

job.sendToSingle(outFilename);

job.sendToNull(fileName);

} else {

job.sendToSingle(fileName);

}

}

}

}







Dwight Kelly

Apago, Inc.

dkelly@apago.com
tkittel
Member
Posts: 50
Joined: Thu Jul 21, 2011 7:30 am

Compare specific properties of two pdf files (beginner)

Post by tkittel »

Hello Dwight,



today I found your code, copied it to the switch script editor and created the script element for the prefix, how you noticed it. Well, what shall I say: "It works perfectly".

So I started to adapt some details and implemented it to my flow. Now I 'only' have to analyze it to understand, how it works ;o)

Thank you very much for this code!



Have a nice day!

Thomas
Post Reply