Copy link to clipboard
Copied
I need some help with adding a snippet to my funcional pdf export plugin that would automatically rename the output pdf file. I tried my best over the weekend and with all the time invested I couldn't make it work.
The very basic plugin I have been using (see below) creates a pdf copy out of the artboard #1, and saves it under the name of the active file, into the home folder of active file. That's exactly what I need, but I have to go into Finder each time and manually change the name of the new created pdf file. So instead of having plugin automatically creating File.pdf I need it to create File-Placard.pdf. Basically renaming it and adding "-Placard" to the active file name. Everything I tried wouldn't work 100%.
If anyone has an idea how to make this happen please let me know.
Thank you for all your help.
MarkA
#target "illustrator" var aiApp = app.activeDocument; dest = aiApp.fullName if (app.documents.length > 0) { var saveOpts = new PDFSaveOptions(); var fileSpec = new File(dest); saveOpts = new PDFSaveOptions(); saveOpts.artboardRange = 1; saveOpts.compatibility = PDFCompatibility.ACROBAT5; saveOpts.generateThumbnails = true; saveOpts.preserveEditability = false; saveOpts.pDFPreset = 'Placard'; aiApp.saveAs(fileSpec, saveOpts) }
Well done! That's much better that you worked it our yourself and I am glad you are using regular expressions! For the sake of extra learning, here's what I was about to reply, which is a slightly more succinct version of yours. It uses a more complex regular expression that looks for the last period in a string (and anything after it).
var suffix = '-Placard';
if (app.documents.length > 0) {
var doc = app.activeDocument;
dest = String(doc.fullName).replace(/(.(?!\.))+$/, suffix);
v
...
Copy link to clipboard
Copied
OK, as soon as I posted this I figured out exactly what I needed.
Copy link to clipboard
Copied
Well done! That's much better that you worked it our yourself and I am glad you are using regular expressions! For the sake of extra learning, here's what I was about to reply, which is a slightly more succinct version of yours. It uses a more complex regular expression that looks for the last period in a string (and anything after it).
var suffix = '-Placard';
if (app.documents.length > 0) {
var doc = app.activeDocument;
dest = String(doc.fullName).replace(/(.(?!\.))+$/, suffix);
var saveOpts = new PDFSaveOptions();
var fileSpec = new File(dest);
saveOpts = new PDFSaveOptions();
saveOpts.artboardRange = 1;
saveOpts.compatibility = PDFCompatibility.ACROBAT5;
saveOpts.generateThumbnails = true;
saveOpts.preserveEditability = false;
saveOpts.pDFPreset = 'Placard';
aiApp.saveAs(fileSpec, saveOpts)
}
- Mark
Copy link to clipboard
Copied
Looks great. Thank you very much.