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

Multiple artboards to multiple PDF's

Explorer ,
Jan 29, 2011 Jan 29, 2011

Copy link to clipboard

Copied

I have over 300 different ai files with about 50 artboards in each one and need to export each artboard to a separate PDF file.  I'm on a windows machine so the script would have to be JavaScript.  Is this possible?

I found the following script on the forums, which is close, but I really need actual PDF files (not just "PDF compatible" ai files):

Thanks so much!

Tim



//splits the activeDocument Artboards into individual files

var doc = app.activeDocument;

var docName = doc.name;
var docPath = doc.path;
var fullName = docPath + "/" + docName;
var abRange = ""

for (i=1; i<=doc.artboards.length;i++)
    {
        abRange = abRange + i + ","
     }
IllustratorSaveOptions.saveMultipleArtboards = true;
IllustratorSaveOptions.artboardRange = abRange;

var newFile = new File(fullName);
app.activeDocument.saveAs (newFile, IllustratorSaveOptions);

alert ("Artboards Saved to current document's Folder", "Split Arboards");

TOPICS
Scripting

Views

15.3K

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

correct answers 1 Correct answer

Guide , Feb 08, 2011 Feb 08, 2011

Replace the last function with…

function renameFiles(dir, fL) {      for (var i = 0; i < fL.length; i++) {                           var f = File(dir.fsName + '/' + fL);                      if (f.exists) {                                          var reName = f.name.replace('_','-');                      f.rename(reName);                                f = File(dir.fsName + '/' + reName);                                reName = f.name.replace(/\.ai$/,'.pdf');                                t =

...

Votes

Translate

Translate
Adobe
Explorer ,
Mar 23, 2011 Mar 23, 2011

Copy link to clipboard

Copied

Mark - I've been using this script alot, and enjoying it, so thanks for the help in setting it up.  I did run into an issue yesterday that I was hoping you could help me with.  I have found that the script only works if there are more than 1 artboards in the document.  Occaisionally (as happened yesterday), we do only have 1 artboard to export.  What line would I tweak to allow the script to work on do

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
Explorer ,
Mar 28, 2011 Mar 28, 2011

Copy link to clipboard

Copied

Mark - is there a way to adjust this script to export only selected artboards (instead of all artboards)?  By selected, I mean in the artbaords pallette where you can make multiple selections.

Thank 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
Guide ,
Mar 28, 2011 Mar 28, 2011

Copy link to clipboard

Copied

I would have to take a look… I would doubt it thou… Artboards are not something I've used very much as I jumped from CS2 to CS5 in the one go… Now it feels like a mountain to climb with so many things I need to either update or learn to use in the GUI first… I would expect the closest may be some sort of dialog with a list to select from. Illustrator revealing what's selected in it's own palettes may be too much to expect…

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
Explorer ,
Mar 30, 2011 Mar 30, 2011

Copy link to clipboard

Copied

Anyone had a chance to look at this?  Basically, the issue we're running into is that if we make a revision to just one artboard (on our master sheet of 50+ artboards), there isn't a good/efficient way of exporting only the revised artboard to ai then change the file name extension to .pdf.  We can't re-export all of the artboards in case we have made comments on the exported individual files that we don't want to be overwritten.

A reminder that when you use Illustrators save as pdf functionality it saves all of the other artboards and shows that information when you open the pdf in Illustrator.  That's why we export as separate AI file then just change the extension, because it actually does remove the data from all other artboards when done this way.

Any help would be greatly appreciated.

Thanks!

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
Guide ,
Mar 30, 2011 Mar 30, 2011

Copy link to clipboard

Copied

If you are talking about outputting just the 1 ai/pdf at a time then you can get the index of the active artboard… So as long as this was the case when the script was run… I thought you may be dealing with a multi-selection of artboards…

alert(app.activeDocument.artboards.getActiveArtboardIndex());

In a quick test this worked fine… Don't forget its zero based… If you did select more than 1 artboard in the palette then it returns the first one selected…

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
Explorer ,
Mar 30, 2011 Mar 30, 2011

Copy link to clipboard

Copied

Multiple artboard selection would be amazing, I wish that would work

However, your recommendation would be a gem as well.  Can you show me where to insert the line of code you provided?

Here's my current script without it:

#target illustrator

function artboardsToPDFs() {

     if (app.documents.length = 0) {

          return;

     } else {

          var docRef = app.activeDocument;
         
          var docName = docRef.name;

          var baseName = docName.replace(/.ai$/,'');

var dF = Folder('S:/Graphics/Manufacturing - Production/Stock Graphics');
       
          var aB = docRef.artboards;
         
          var autoNames = Array();
         
          for (var i = 0; i < aB.length; i++) {
         
               var abName = aB.name;
         
               autoNames.push(baseName + '_' + abName + '.ai');
         
          }
         
          if (!docRef.saved) docRef.save();
         
          var aiOpts = new IllustratorSaveOptions();
         
          aiOpts.compatibility = Compatibility.ILLUSTRATOR13;
          aiOpts.pdfCompatible = true;
          aiOpts.saveMultipleArtboards = true;
         
          var saveFile = File(dF.fsName + '/' + docName);
         
          docRef.saveAs(saveFile, aiOpts);
         
          docRef.close(SaveOptions.DONOTSAVECHANGES);
         
          saveFile.remove();
         
          renameFiles(dF, autoNames);
     }
}

artboardsToPDFs();


function renameFiles(dir, fL) {

     for (var i = 0; i < fL.length; i++) {
              
          var f = File(dir.fsName + '/' + fL);
         
          if (f.exists) {
                        
               var reName = f.name.replace('_','-');
    
               f.rename(reName);
              
               f = File(dir.fsName + '/' + reName);
              
               reName = f.name.replace(/\.ai$/,'.pdf');
              
               t = File(dir.fsName + '/' + reName);
              
               if (t.exists) t.remove();
    
               f.rename(reName);
              
          }
     }
}

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
Guide ,
Mar 30, 2011 Mar 30, 2011

Copy link to clipboard

Copied

Tim, give this a test… I had a quick go and think I remember what we were doing…

#target illustrator function artboardToPDF() {      if (app.documents.length = 0) {           return;      } else {           var docRef = app.activeDocument;                     var docName = docRef.name;           var baseName = docName.replace(/.ai$/,'');           var dF = Folder('~/Desktop');                   var aBI = docRef.artboards.getActiveArtboardIndex();                      var aBName = docRef.artboards[aBI].name;                        if (!docRef.saved) docRef.save();                     var aiOpts = new IllustratorSaveOptions();                     aiOpts.compatibility = Compatibility.ILLUSTRATOR13;           aiOpts.pdfCompatible = true;           aiOpts.saveMultipleArtboards = true;           aiOpts.artboardRange = aBI + 1;                     var saveFile = File(dF.fsName + '/' + docName);                     docRef.saveAs(saveFile, aiOpts);                      var autoName = File(dF.fsName + '/' + baseName + '_' + aBName + '.ai');                      if (autoName.exists) {                                var newName = autoName.name.replace('_','-');                                newName = newName.replace(/\.ai$/,'.pdf');                                autoName.rename(newName);                           }                     docRef.close(SaveOptions.DONOTSAVECHANGES);               } } artboardToPDF();

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
Explorer ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

Hi Mark -

Digging up an oldie but a goodie...we still use this script (and variations of it) day in and day out.  Have for years since you originally help us get this together.  Still can't thank you enough for your contribution here.

We now have a master file naming format that is instead of what used to be "105.ai"....it is now "105 (ID 58).ai", but we still need the exported artboards to be named 105-15.pdf  (where "15" is the actual artboard name being exported).  So basically, we need to update the scripts to ignore any spaces in the file name and ignore EVERYTHING that is inside of parenthesis (including the parenthesis) in the filename.

Below is only a tiny snip of the whole code...but I'm wondering if we can change line 03 to something like this:

    var newName = autoName.name.replace(' ('*')*_','-');  ??  I know that this (as shown) wouldn't work...but is there a way to accomplish this simply?  Just need to strip the " (ID 144)" portion of the exported filename.

  1. if (autoName.exists) { 
  2.                 
  3.                var newName = autoName.name.replace('_','-'); 
  4.                 
  5.                newName = newName.replace(/\.ai$/,'.pdf'); 
  6.                 
  7.                autoName.rename(newName); 
  8.                 
  9.           } 

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
Guide ,
Aug 18, 2015 Aug 18, 2015

Copy link to clipboard

Copied

you just need a more complex regex.

not sure this is the best and cleanest way of writing it, but it should do the trick

I included some explanation on what each part does.

               var newName = autoName.name.replace('_','-');   

                   //   \s  match whitespace

                   //   \(  match Bracket

                   //   [\d\w\s]*   match digit, word char or white space * makes it match as many as it can find

                   //   \)  match Bracket

                   //   \.ai    match .ai

                   //   $   do all the above at the end of the string

               newName = newName.replace(/\s\([\d\w\s]*\)\.ai$/,'.pdf');  

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
Explorer ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

Thanks so much for the reply.  I tried using those lines in the script, but the exported artboards are not being renamed correctly.

Original MASTER FILE illustrator filename:  102 (ID 185).ai

Artboard name that is being exported: 70B

Desired file name:  102-70B.pdf

Here is the outputted file name using code from post #58:  102 (ID 185)-70B.ai

Here is the entire code:

#target illustrator

function artboardToPDF() {

     if (app.documents.length = 0) {

          return;

     } else {

          var docRef = app.activeDocument;

       

          var docName = docRef.name;

          var baseName = docName.replace(/.ai$/,'');

  var dF = Folder(Folder.desktop + "/AI PDF's");

     

          var aBI = docRef.artboards.getActiveArtboardIndex();

       

          var aBName = docRef.artboards[aBI].name;

          

          if (!docRef.saved) docRef.save();

       

          var aiOpts = new IllustratorSaveOptions();

       

          aiOpts.compatibility = Compatibility.ILLUSTRATOR13;

          aiOpts.pdfCompatible = true;

          aiOpts.saveMultipleArtboards = true;

          aiOpts.artboardRange = aBI + 1;

       

          var saveFile = File(dF.fsName + '/' + docName);

       

          docRef.saveAs(saveFile, aiOpts);

       

          var autoName = File(dF.fsName + '/' + baseName + '_' + aBName + '.ai');

       

          if (autoName.exists) {

            

               var newName = autoName.name.replace('_','-');   

                   //   \s  match whitespace

                   //   \(  match Bracket

                   //   [\d\w\s]*   match digit, word char or white space * makes it match as many as it can find

                   //   \)  match Bracket

                   //   \.ai    match .ai

                   //   $   do all the above at the end of the string

               newName = newName.replace(/\s\([\d\w\s]*\)\.ai$/,'.pdf');     

            

               autoName.rename(newName);

            

          }

       

      

     }

}

artboardToPDF();

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
Explorer ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

Any ideas how I can get the exported and renamed files to ignore the " (ID 185)" portion of the original filename?  Just need to subract 1 space before and anything contained within parentheses.  Thoughts?

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
Guide ,
Aug 19, 2015 Aug 19, 2015

Copy link to clipboard

Copied

If a bit confused on what is going on with the script as it looks like you are just renaming the .ai file to a .pdf rather then saving a pdf.

but I am prob missing something.

I did not know the artboard name was already part of the string.

lets try doing the replace on the baseName then rebuild the file name

so if you replace your whole if exists statement with this it should work.

only tested on a string and not in context so no guarantees.

          if (autoName.exists) { 

              

               strippedBaseName = baseName.replace(/\s\([\d\w\s]*\)$/,'');       

              

               autoName.rename(dF.fsName + '/' + strippedBaseName + '-' + aBName + '.pdf'); 

              

          }

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
Explorer ,
Aug 20, 2015 Aug 20, 2015

Copy link to clipboard

Copied

That is perfect!  Thanks so much. 

Now I'm trying to translate this to another set of scripts that does exactly the same thing, except they export ALL of the artboards on the master AI file.  The script is a little different...would I need to put a new line at Line 16 below to strip the basename of the parenthetical characters (ie...." (ID 185)")?  Would any other lines need revision as well?

#target illustrator

function artboardsToPDFs() {

     if (app.documents.length = 0) {

          return;

     } else {

          var docRef = app.activeDocument;

         

          var docName = docRef.name;

          var baseName = docName.replace(/.ai$/,'');

var dF = Folder('S:/Graphics/Manufacturing - Production/Stock Graphics');

       

          var aB = docRef.artboards;

         

          var autoNames = Array();

         

          for (var i = 0; i < aB.length; i++) {

         

               var abName = aB.name;

         

               autoNames.push(baseName + '_' + abName + '.ai');

         

          }

         

          if (!docRef.saved) docRef.save();

         

          var aiOpts = new IllustratorSaveOptions();

         

          aiOpts.compatibility = Compatibility.ILLUSTRATOR13;

          aiOpts.pdfCompatible = true;

          aiOpts.saveMultipleArtboards = true;

         

          var saveFile = File(dF.fsName + '/' + docName);

         

          docRef.saveAs(saveFile, aiOpts);

         

          docRef.close(SaveOptions.DONOTSAVECHANGES);

         

          saveFile.remove();

         

          renameFiles(dF, autoNames);

     }

}

artboardsToPDFs();

function renameFiles(dir, fL) {

     for (var i = 0; i < fL.length; i++) {

              

          var f = File(dir.fsName + '/' + fL);

         

          if (f.exists) {

                        

               var reName = f.name.replace('_','-');

    

               f.rename(reName);

              

               f = File(dir.fsName + '/' + reName);

              

               reName = f.name.replace(/\.ai$/,'.pdf');

              

               t = File(dir.fsName + '/' + reName);

              

               if (t.exists) t.remove();

    

               f.rename(reName);

              

          }

     }

}

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
Guide ,
Aug 20, 2015 Aug 20, 2015

Copy link to clipboard

Copied

use the same line of code from my previous post.

after you take the .ai off leaving you with baseName.

add the line 3 from the last post to remove the " (******)"

then scan through your code and wherever your building the file name use the strippedBaseName instead of baseName.

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
Explorer ,
Feb 21, 2017 Feb 21, 2017

Copy link to clipboard

Copied

Hi Qwertyfly, I'm hoping you're still around   Back in 2015 you helped me adjust a script that works great, and I'm needing to revisit your post #63 here because I don't think we every got that one completely working.

Is it possible that you could copy and paste my script in my post #62 with the changes you mentioned in post #63?  I'm not great at this and it sounds like a very easy change...I'm just at a loss. 

Thanks in advance for any help!

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
Guide ,
Feb 27, 2017 Feb 27, 2017

Copy link to clipboard

Copied

this is 100% untested.

Hope it works...

#target illustrator 

 

function artboardsToPDFs() { 

 

     if (app.documents.length = 0) { 

 

          return; 

 

     } else { 

 

          var docRef = app.activeDocument; 

           

          var docName = docRef.name; 

 

          var baseName = docName.replace(/.ai$/,'');

  ; added this line -----------------------------------------

  strippedBaseName = baseName.replace(/\s\([\d\w\s]*\)$/,'');

  baseName = strippedBaseName;

  ;----------------------------------------------------------

 

var dF = Folder('S:/Graphics/Manufacturing - Production/Stock Graphics'); 

         

          var aB = docRef.artboards; 

           

          var autoNames = Array(); 

           

          for (var i = 0; i < aB.length; i++) { 

           

               var abName = aB.name; 

           

               autoNames.push(baseName + '_' + abName + '.ai'); 

           

          } 

           

          if (!docRef.saved) docRef.save(); 

           

          var aiOpts = new IllustratorSaveOptions(); 

           

          aiOpts.compatibility = Compatibility.ILLUSTRATOR13; 

          aiOpts.pdfCompatible = true; 

          aiOpts.saveMultipleArtboards = true; 

           

          var saveFile = File(dF.fsName + '/' + docName); 

           

          docRef.saveAs(saveFile, aiOpts); 

           

          docRef.close(SaveOptions.DONOTSAVECHANGES); 

           

          saveFile.remove(); 

           

          renameFiles(dF, autoNames); 

     } 

 

artboardsToPDFs(); 

 

 

function renameFiles(dir, fL) { 

 

     for (var i = 0; i < fL.length; i++) { 

                

          var f = File(dir.fsName + '/' + fL); 

           

          if (f.exists) { 

                          

               var reName = f.name.replace('_','-'); 

      

               f.rename(reName); 

                

               f = File(dir.fsName + '/' + reName); 

                

               reName = f.name.replace(/\.ai$/,'.pdf'); 

                

               t = File(dir.fsName + '/' + reName); 

                

               if (t.exists) t.remove(); 

      

               f.rename(reName); 

                

          } 

     } 

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
Explorer ,
Feb 28, 2017 Feb 28, 2017

Copy link to clipboard

Copied

Thank you so much for the reply.  Unfortunately, it did not rename the files.

Original AI filename (containing 80+ artboards):  101 (ID 2424).ai

Expected resulting filename example (1 of the 80 boards exported):  101-11.PDF

Actual resulting filename example (1 of the 80 boards exported):  101 (ID 2424)_11.ai

Any ideas what other lines/locations I may need to add in to get the resulting files renamed?

Thank you so much!

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
Guide ,
Feb 28, 2017 Feb 28, 2017

Copy link to clipboard

Copied

line 32 has a string made from baseName and then some other stuff.

change the underscore to a dash.

the id number still in the file name suggests an issue with the regex in the replace. shown on the line i added.

ill take a look at the reg when back on the 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
Guide ,
Feb 28, 2017 Feb 28, 2017

Copy link to clipboard

Copied

Line 15 replaces ".ai" with a space.

my regex does not look for this space.

remove the space between the quotes on line 15.

further down you have a function to rename files. it does a replace in there that does the underscore to dash.

if we fix the regex that should work so ignore the previous post about line 32.

side note: in the renaming function you rename an ai file to a pdf file.

does this work?

I would be saving as a pdf, not just renaming the extension.

am I missing something???

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
Explorer ,
Apr 07, 2017 Apr 07, 2017

Copy link to clipboard

Copied

Thanks so much, and my apologies for just now seeing this.  This will be immensely helpful if it works.  I will try this out shortly.

Totally understand the question regarding changing the name from .ai to .pdf...yes, it does work.  They are basically the same thing.  What we gain is the ability to keep full Illustrator data in the file and the entire group can "open" pdf files and view them (without having illustrator). 

I will post back in shortly after trying this code out...

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
Explorer ,
Apr 07, 2017 Apr 07, 2017

Copy link to clipboard

Copied

LATEST

On line 15, I'm not seeing a space between the quotes:

      var baseName = docName.replace(/.ai$/,'');


Is this the line you are referring 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
New Here ,
Mar 03, 2016 Mar 03, 2016

Copy link to clipboard

Copied

Realy its Working Awsome ....for Ai and PDF please can any one give me a solution for PNG

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