// Main Code [Execution of script begins here] try { // uncomment to suppress Illustrator warning dialogs // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; if (app.documents.length > 0) { var options, i, sourceDoc, targetFile, OLtargetFile; showDlg(); if (!options) { 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 showDlg() { var dlg = new Window('dialog', 'Script Information', [90, 50, 300, 175]); dlg.buildBtn = dlg.add('button', [10, 95, 90, 120], 'Create PDF', { name: 'ok' }) dlg.cancelBtn = dlg.add('button', [105, 95, 190, 120], 'Cancel', { name: 'cancel' }) dlg.Dbtn = dlg.add('radiobutton', [50, 5, 295, 30], 'PDF 1.3 (Default)'); dlg.Ibtn = dlg.add('radiobutton', [50, 30, 320, 55], 'PDF 1.6 (Advanced)'); dlg.Dbtn.value = true; dlg.buildBtn.onClick = savePDF; dlg.center(); dlg.show(); } function savePDF() { // Create the required options object // You can tune these by changing the code in the getOptions() function. this.parent.close(); // See PDFSaveOptions in the JavaScript Reference for available options // Set the options you want below: // 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; options = new PDFSaveOptions(); if (this.parent.Dbtn.value) { options.pDFPreset = "Default" } else { options.pDFPreset = "Advanced" } 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 = getTargetFile(sourceDoc.name, '_Live.pdf', destFolder); OLtargetFile = getTargetFile(sourceDoc.name, '_Outlined.pdf', destFolder); //sourceDoc.save(); // Save as pdf sourceDoc.saveAs(targetFile, options); FlattenOutline(); sourceDoc.saveAs(OLtargetFile, options) alert('Documents saved as PDF'); } function FlattenOutline() { var set = 'script action', action = 'outline text'; createAction(); for (i = 0; i < sourceDoc.layers.length; i++) { app.selection = null; sourceDoc.layers.locked = false; sourceDoc.layers.hasSelectedArtwork = true; app.doScript(action, set); } app.unloadAction(set, ''); } function createAction() { var actionStr = '/version 3/name [13 73637269707420616374696f6e]/actionCount 1/action-1 {/name [12 6f75746c696e652074657874]/eventCount 1/event-1 {/internalName (ai_plugin_flatten_transparency)/hasDialog 1/showDialog 0/parameterCount 5/parameter-1 {/key 1920169082/type (integer)/value 100}/parameter-2 {/key 1919253100/type (unit real)/value 1200.0/unit 592342629}/parameter-3 {/key 1869902968/type (boolean)/value 1}/parameter-4 {/key 1869902699/type (boolean)/value 0}/parameter-5 {/key 1667463282/type (boolean)/value 0}}}'; f = File('~/tmp.aia'); f.open('w'); f.write(actionStr); f.close(); app.loadAction(f); f.remove(); } /** 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; } Note that each layer will become one group due to flatten transparency.
... View more