if (pdfFiles.length>0)
{
//run photoshop
var psScript="#target photoshop\r\n";
psScript+="app.displayDialogs = DialogModes.NO;\r\n";
psScript+="app.preferences.rulerUnits = Units.MM;\r\n";
psScript+="var openOptions = new PDFOpenOptions;\r\n";
psScript+="openOptions.bitsPerChannel=BitsPerChannelType.EIGHT;\r\n";
psScript+="openOptions.mode=OpenDocumentMode.RGB;\r\n";
psScript+="openOptions.cropPage=CropToType.CROPBOX;\r\n";
psScript+="openOptions.resolution=300;\r\n";
psScript+="openOptions.suppressWarnings=true;\r\n";
psScript+="var myFiles=new Array();\r\n";
for(var j=0;j<pdfFiles.length;j++)
{
psScript+="myFile=new Object();\r\n";
psScript+="myFile.file=new File(\""+pdfFiles[j].file+"\");\r\n";
psScript+="myFile.crop=["+pdfFiles[j].crop+"];\r\n";
psScript+="myFiles.push(myFile);\r\n";
}
psScript+="for (var i=0;i<myFiles.length;i++) {\r\n";
psScript+="docRef=open(myFiles[i].file,openOptions);\r\n";
psScript+="docRef.crop([UnitValue(myFiles[i].crop[1],\"mm\"),UnitValue(myFiles[i].crop[0],\"mm\"),UnitValue(myFiles[i].crop[3],\"mm\"),UnitValue(myFiles[i].crop[2],\"mm\")]);\r\n";
psScript+="docRef.saveAs(File(myFiles[i].file.fullName.substring(0,myFiles[i].file.fullName.lastIndexOf(\".\"))+\".png\"), new PNGSaveOptions, true);\r\n";
psScript+="docRef.close(SaveOptions.DONOTSAVECHANGES);\r\n";
psScript+="myFiles[i].file.remove();"
psScript+="}\r\n";
psScript+="app.displayDialogs = DialogModes.ALL;\r\n";
app.doScript(psScript);
}