Hi All,
I am currently working on a script (editing one we currently use) that will allow me to export Outlined and Live version at the same time (using Illustrator CS4 and CS6). I've basic knowledge about scripting.
See screenshot below, what I am trying to achieve:
Here's what I've done so far:
// Main Code [Execution of script begins here]
var modUI = 'D';
try {
// uncomment to suppress Illustrator warning dialogs // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; if (app.documents.length > 0 ) { // Get the folder to save the files into var options, i, sourceDoc, targetFile; // Get the PDF options to be used options = this.getOptions(); if (options != null) { // You can tune these by changing the code in the getOptions() function. sourceDoc = app.activeDocument; // returns the document object var fullName = sourceDoc.fullName; fullName = fullName.toString(); var destFolder = fullName.slice(0,fullName.lastIndexOf("/")) // Get the file to save the document as pdf into targetFile = this.getTargetFile(sourceDoc.name, '_Live.pdf', destFolder); OLtargetFile = this.getTargetFile(sourceDoc.name, '_Outlined.pdf', destFolder); sourceDoc.save(); // Save as pdf sourceDoc.saveAs( targetFile, options ); for(q=0; q<sourceDoc.layers.length;q++){ sourceDoc.layers[q].locked = false } for(q=0; q<sourceDoc.pageItems.length;q++){ try { sourceDoc.pageItems[q].createOutline(); } catch(e){} } sourceDoc.saveAs( OLtargetFile, options) alert( 'Documents saved as PDF' ); } else { alert('User aborted') } } else{ throw new Error('There are no document open!'); }
}
catch(e) { alert( e.message, "Script Alert", true);
}
/** Returns the options to be used for the generated files.
@return PDFSaveOptions object
*/
function getOptions()
{ var dlg = new Window('dialog', 'Script Information',[90,50,300,175]); dlg.include = dlg.add('radiobutton',[50,5,295,30], 'PDF 1.3 (Default)'); dlg.include = dlg.add('radiobutton',[50,30,320,40], 'PDF 1.6 (Advanced)'); dlg.buildBtn = dlg.add('button',[10,95,90,27], 'Create PDF', {name:'ok'}) dlg.cancelBtn = dlg.add('button',[105,95,190,47], 'Cancel', {name:'cancel'}) dlg.include.onClick = radioSwitch; dlg.cancelBtn.onClick = abortFunction; dlg.center(); dlg.show(); // Create the required options object var options = new PDFSaveOptions(); // See PDFSaveOptions in the JavaScript Reference for available options // Set the options you want below: if (modUI == 'D'){ options.pDFPreset = "Default" } else if (modUI == 'I'){ options.pDFPreset = "Advanced" } else { options = null; } // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6) // options.compatibility = PDFCompatibility.ACROBAT7; // For example, uncomment to view the pdfs in Acrobat after conversion // options.viewAfterSaving = true; return options;
}
function radioSwitch(){
if (modUI == 'D') { modUI = 'I' } else { modUI = 'D' }
}
function abortFunction(){
modUI = null; dlg.hide(); return null; }
/** Returns the file to save or export the document into. @param docName the name of the document @param ext the extension the file extension to be applied @param destFolder the output folder @return File object
*/
function getTargetFile(docName, ext, destFolder) { var newName = ""; // if name has no dot (and hence no extension), // just append the extension if (docName.indexOf('.') < 0) { newName = docName + ext; } else { var dot = docName.lastIndexOf('.'); newName += docName.substring(0, dot); newName += ext; } // Create the file object to save to var myFile = new File( destFolder + '/' + newName ); // Preflight access rights if (myFile.open("w")) { myFile.close(); } else { throw new Error('Access is denied'); } return myFile;
}
Any help appreciated!
Pete