Copy link to clipboard
Copied
Hi!
I'm total new in scripting but i've somehow managed to do an export script which exports highres and lowres pdf's.
Only problem is that it overwrites existing pdfs. Can someone help me and write a script in javascript which adds versionumber after pdf name?
Like if there's already PDF named xxx_LOW it makes xxx_LOW_v2, xxx_LOW_v3 and so on.
Thanks!
This was an easy task to integrate within your script. I would have liked it more if you would have tried it a bit more, that would have been a better learning experience for you. However in order to complete the issue at hand, i list below that changes that you need to do in your script for this integration.
1. Create a method with the code that i gave, function is a better approach as you need to use the same piece of code twice(once to get the hires pdf and then the low res pdf export path). S
...Copy link to clipboard
Copied
You could try the following code to identify the export path according to your conditions
var fName = "xxx_LOW"
var exportFolder = "/users/eternal_grape/Desktop/test/" //Change this to the folder where you want the export to happen
var exportPath = new File(exportFolder + fName + ".pdf")
var counter = 2
while(exportPath.exists)
{
exportPath = new File(exportFolder + fName + counter + ".pdf")
counter++
}
alert("Your exportpath is " + exportPath) //At this point the exportPath has the path on which you need to export the pdf
Copy link to clipboard
Copied
Hi! Thanks for quick reply!
This is the script i've been using.
d = app.activeDocument;
preset1 = app.pdfExportPresets.itemByName("HiRes");
preset2 = app.pdfExportPresets.itemByName("LoRes");
if (!(preset1.isValid && preset2.isValid)){
alert("One of the presets does not exist. Please check spelling carefully.");
exit();
}
mDocName = d.name.substr (0, d.name.lastIndexOf('.'));
mSourcePath = d.fullName.parent.toString();
mRootPath =mSourcePath.substr (0, mSourcePath.lastIndexOf('/'));
mTargetPath=mRootPath.concat('/PDF-Low/');
mNameWeb= mTargetPath.concat(mDocName,'_LR.pdf');
mTargetPath=mRootPath.concat('/PDF-High/');
mNamePrint = mTargetPath.concat(mDocName,'_HR.pdf');
if (!d.saved){
d.save;
}
d.exportFile(ExportFormat.PDF_TYPE, new File(mNamePrint), false, preset1);
d.exportFile(ExportFormat.PDF_TYPE, new File(mNameWeb), new, preset2);
});
I tried your code, but I need it to save it to folder where i'm currently working so there's no default folder for the pdfs. Also the file name changes. Sorry i was little bit unclear
Copy link to clipboard
Copied
This was an easy task to integrate within your script. I would have liked it more if you would have tried it a bit more, that would have been a better learning experience for you. However in order to complete the issue at hand, i list below that changes that you need to do in your script for this integration.
1. Create a method with the code that i gave, function is a better approach as you need to use the same piece of code twice(once to get the hires pdf and then the low res pdf export path). So paste the following in your code file
function getExportPath(exportFolder, fName)
{
var exportPath = new File(exportFolder + fName + ".pdf")
var counter = 2
while(exportPath.exists)
{
exportPath = new File(exportFolder + fName + counter + ".pdf")
counter++
}
return exportPath
}
2. Now in your code replace the following lines
mNameWeb= mTargetPath.concat(mDocName,'_LR.pdf');
//Replace the above with
mNameWeb= getExportPath(mTargetPath, mDocName + '_LR');
//Similarly do the same for HR PDF
mNamePrint = mTargetPath.concat(mDocName,'_HR.pdf');
//Replace the above line with
mNamePrint = getExportPath(mTargetPath, mDocName + '_HR');
This should do it hopefully
Copy link to clipboard
Copied
Nice!!! I got it working! Thanks for helping me!