• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with script: export to Live and Outlined versions

Participant ,
Mar 30, 2016 Mar 30, 2016

Copy link to clipboard

Copied

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:

Screen Shot 2016-03-30 at 12.37.08.png 

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.locked = false

  }

  for(q=0; q<sourceDoc.pageItems.length;q++){

  try {

  sourceDoc.pageItems.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

TOPICS
Scripting

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Participant ,
May 13, 2016 May 13, 2016

Copy link to clipboard

Copied

up

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 13, 2016 May 13, 2016

Copy link to clipboard

Copied

Whoa , how did you create such a diagram?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 13, 2016 May 13, 2016

Copy link to clipboard

Copied

Hi Silly-V,

Yes I did! Always like to visualise and document my goal. Obviously going over the top with details sometimes (progress bar), but overall I think it's good to have a big picture!

I have a general sense of the script but unfortunately my scripting abilities reached the point where I am not able to move on with some of the functions.

Thank you for your interest though!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 13, 2016 May 13, 2016

Copy link to clipboard

Copied

So you drew it all yourself in AI?

How about your progress bar, is it not only going to show you only 1 file? Or are you talking about a saving-pdf progress bar, in which case I think one appears automatically anyways.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 14, 2016 May 14, 2016

Copy link to clipboard

Copied

All in Ai, I am using it on a daily basis after all!

The script will work only on the open file (single PDF). Once I finish working on the file (still keeping it open), I'll execute the script.

The Progress bar will show the progress of  exporting to Live and Outline PDF of the single file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 17, 2016 May 17, 2016

Copy link to clipboard

Copied

So your progress bar is just going to be the native progress bar Illustrator shows, right. So what's wrong with it so far? Looks like all the parts are there from a brief look-over.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 17, 2016 May 17, 2016

Copy link to clipboard

Copied

Hi Silly,

I see no progress bar anyways. Let's forget about the bar. I wanted to focus more on the code itself. There is an issue, it hangs when running it on Windows PC.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2016 May 19, 2016

Copy link to clipboard

Copied

I am not so good at scripting but you can achieve this using a combination of script and actions.

1. create an action

2. use javascript to save the ai file to pdf using save as script

3. create outlined pdf using export option. This can be achieved through a free plugin called "Esko Dataexchange" and this saves the file as normalised pdf which is as similar to pdf

Hope this helps you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 22, 2016 May 22, 2016

Copy link to clipboard

Copied

I don't want use any external plug-ins, especially if this procedure can be achieved by pure scripting. Especially when it comes to work on other machines (Mac or PC).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 22, 2016 May 22, 2016

Copy link to clipboard

Copied

A work version with no bar. make sure the "Default" and "Advanced" presets exist in your PDFSaveOptions presets list, and name are correct.

// 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);

    for (i = 0; i < sourceDoc.layers.length; i++) {

        sourceDoc.layers.locked = false

    }

    for (i = 0; i < sourceDoc.pageItems.length; i++) {

        try {

            sourceDoc.pageItems.createOutline();

        } catch (e) {}

    }

    sourceDoc.saveAs(OLtargetFile, options)

    alert('Documents saved as PDF');

}

/** 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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 23, 2016 May 23, 2016

Copy link to clipboard

Copied

moluapple​ this is working pretty well! However I realized, that sometimes when using Symbols together with Transform Effect: It won't outline as it supposed to

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2016 May 23, 2016

Copy link to clipboard

Copied

Yes, always be careful when create outline of texts. It's more safe to using transparency flattener to outline text.

With CS6+ version . you can execute a action to outline all text using transparency flattener in your script. I'll show you how if use CS6+ is ok for you.

But with CS4, what you can play with script is to set the flattenerOptions of the PDFSaveOptions to outline all text, which limited to PDF 1.3.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 24, 2016 May 24, 2016

Copy link to clipboard

Copied

Sure, will be very helpful to see how it's done in CS6!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

// 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 26, 2016 May 26, 2016

Copy link to clipboard

Copied

moluapple​ works fantastic in CS6! I see that you are using key parameters. I also understand that you can call it through:

app.executeMenuCommand('Flatten Transparency');

Unfortunately MenuCommand won't work in CS4 which is a bummer!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 26, 2016 May 26, 2016

Copy link to clipboard

Copied

LATEST

That MenuCommand only open the UI dialog for you, which is useless in the script. I'm using action instead, also CS6+ only.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2016 May 22, 2016

Copy link to clipboard

Copied

I think this can be achieved through scripts also. Please refer the below link

KB127271486: DeskPack - How to script the Export to Normalized PDF file in Adobe® Illustrator® - Kno...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines