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

Multiple artboards to multiple PDF's

Explorer ,
Jan 29, 2011 Jan 29, 2011

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
17.9K
Translate
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 =

...
Translate
Adobe
Community Expert ,
Feb 06, 2011 Feb 06, 2011

can you post a screen shot showing your Artboards palette?

Translate
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 07, 2011 Feb 07, 2011

artboardpallete.jpg

No problem.  Just curious, do you have another idea?  Does my previous post make sense?

Translate
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
Community Expert ,
Feb 07, 2011 Feb 07, 2011

I do, you can accomplish it without scripting. Just save your master file (102.ai) and check the option "Save each artboard as separate file". That will give you

102.ai

102_21.ai

102_70.ai

102_71.ai

102_74.ai

102_80.ai

etc...

then, go to Bridge, select the files and batch rename to PDF.

Translate
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 07, 2011 Feb 07, 2011

That does work to prove it is possible to export artboards to separate AI files.  But we need to automate the task into one

step because we revise about 10-20 different master AI files each day (and export the artboards).  Just need one step to

save the master file, export the artboards to separate AI files, and have those exported ai files renamed to .pdf.

Really the last step is another script that constantly runs through the destination folder to automatically rename any AI file with .pdf

Also, need the name of the exported files to be 102-11.ai instead of an underscore (102_11.ai), and I think that can only be done via a script.  Right?

Translate
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
Community Expert ,
Feb 07, 2011 Feb 07, 2011

saving artboards to separate files is proven, that's what my script in your first post do...now renaming...I think is possible too.

How is the scriptlance bidding going? I can't believe we're here scratching our heads trying to find a solution and there's someone willing and able to do it for $10...I guess they know they're doing.

Translate
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 08, 2011 Feb 08, 2011

Carlos, that option added to the Illustrator save options was well spotted… I looked everywhere or so I thought!!!! for something like that. Anyhows it is available to scripting too. So if you don't mind renamed '.ai' files as '.pdf' then the job is very easy now. Here how I would change the names of a folder of files…

#target illustrator var dF = Folder('~/Desktop'); var f = Folder.selectDialog('Where are the AI files?',dF); var fL = f.getFiles(/.ai$/); for (var i = 0; i < fL.length; i++) {            fL.rename(fL.name.replace('-','_'));            fL.rename(fL.name.replace(/.ai$/,'.pdf')); }

Of cause you would not bother will any of that selection stuff and just add this after the save so its all done in the one go…

Translate
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 08, 2011 Feb 08, 2011

Oh wow - that's great if I can do it all at the same time.

Mark - from post #5, what lines do I need to update in that script to change the export to .ai files, and then add your new rename script to it?

I'd much rather use this solution than the "monitor a folder and rename" solution I mentioned earlier.  I just need a little help tieing this all together.

Thanks so much guys!!

Translate
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 08, 2011 Feb 08, 2011

Tim, Im at work at the moment n Im stuck with CS2 when at this junk box… Given Carlos's save method for splitting… The revised script is as good as done (Well so I think!!!). The only part I have NOT put in place yet is the savePath… As Im unsure how you are expected to pass a single path for multi files. I can however check this out later… when I get home… Here is how I was trying to go about 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(Folder.desktop + "/AI PDF's");                     if (!dF.exists) dF.create();                     var aB = docRef.artboards;                     var outFiles = Array();                     for (var i = 0; i < aB.length; i++) {                          outFiles.push(File(dF.fsName + '/' + baseName + '-' + abName + '.ai'));                     }                     var aiOpts = new IllustratorSaveOptions();                     aiOpts.compatability = Compatability.ILLUSTRATOR13;           aiOpts.pdfCompatible = true;           aiOpts.saveMultipleArtboards = true;                     var saveFile = File(dF.fsName + '/' + docName);                     docRef.saveAs(saveFile, aiOpts);                     renameFiles(outFiles);      } } artboardsToPDFs(); function renameFiles(fL) {      for (var i = 0; i < fL.length; i++) {                     if (fL.exists) {                     fL.rename(fL.name.replace('-','_'));                     fL.rename(fL.name.replace(/\.ai$/,'\.pdf'));                          }      } }

It may however choke at the saveAs() line?

Translate
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 08, 2011 Feb 08, 2011

Thanks so much Mark.  Getting an error at line 27.  See attached.

error.jpg

Translate
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 08, 2011 Feb 08, 2011

Yup I missed aline out when cutting and pasting (no artboards here to test with)…

#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(Folder.desktop + "/AI PDF's");                     if (!dF.exists) dF.create();                     var aB = docRef.artboards;                     var outFiles = Array();                     for (var i = 0; i < aB.length; i++) {                          var abName = aB.name;                          outFiles.push(File(dF.fsName + '/' + baseName + '-' + abName + '.ai'));                     }                     var aiOpts = new IllustratorSaveOptions();                     aiOpts.compatability = Compatability.ILLUSTRATOR13;           aiOpts.pdfCompatible = true;           aiOpts.saveMultipleArtboards = true;                     var saveFile = File(dF.fsName + '/' + docName);                     docRef.saveAs(saveFile, aiOpts);                     renameFiles(outFiles);      } } artboardsToPDFs(); function renameFiles(fL) {      for (var i = 0; i < fL.length; i++) {                     if (fL.exists) {                     fL.rename(fL.name.replace('-','_'));                     fL.rename(fL.name.replace(/\.ai$/,'\.pdf'));                          }      } }

Translate
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 08, 2011 Feb 08, 2011

Now line 35 saying Compatability is underfined.  See attached.

Thanks again!

error2.jpg

Translate
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 08, 2011 Feb 08, 2011

It's probably best waiting until I get home if you can be bothered try putting two slashes // at the front of that line to comment it out? What Am I on about its a typo 'Compatability' should of cause be 'Compatibility' in both cases… That's why a muppet…

Translate
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 08, 2011 Feb 08, 2011

Thanks Mark.  I'll wait for you to get home because there are still a few issues after commenting out line 35.

  • The exported artboards are being named 102_11.ai instead of 102-11.ai
  • The master AI file (with all artboards named 102.ai) is being re-saved into the location of the exported files instead of the location where the master files live and is not being saved/updated in its original location.  I need to make sure the master doesn't get saved to the exported destination so it doesn't get mixed in with the individual artboards.
  • The renaming from .ai to .pdf is not happening.

Thanks so much for your help!  You rock.

Translate
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 08, 2011 Feb 08, 2011

Yeah most of that I pretty much expected… It's difficult when you haven't got anything in front of you… This does however do all of your request at this end… Let me know how you get on…

#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(Folder.desktop + "/AI PDF's");           if (!dF.exists) dF.create();                      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');                      f.rename(reName);                           }      } }

The name replacement is based on you having named your artboards… Had you not it will be broken by Illustrators auto numbering. What is nice is the dialog about replacing files better that my Q&A…

Translate
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 08, 2011 Feb 08, 2011

This is great.  One thing that I guess hadn't thought through very well...once the .pdf file exists, how to replace the pdf file with the newer .pdf when we export changes.  Right now, if the .pdf file exists in the folder, it can't rename the new .ai files to pdf because the filename already exists. 

Any ideas?

Translate
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
Community Expert ,
Feb 08, 2011 Feb 08, 2011

Hi Mark, you really rock!!, the script works beautifully...it took a couple of seconds but no chocking with my humble 5 artboard test, let see how it goes with the real world file.

I took the liberty of fixing the errors for you, I swapped the underscore with the dash, and added a couple of lines to include the artboardRange property, you would have easily spotted if you had CS5.

a couple of notes on the whole exercise,

saving as...and checking the option to use "All" artboards in the UI (empty string in JS), saves the active file + all separate artboards. Entering the Range manually 1-5 for example, saves only the arboards, and leaves the active document alone and open.

#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(Folder.desktop + "/AI PDF's");
         
          if (!dF.exists) dF.create();
         
          var aB = docRef.artboards;
         
          var outFiles = Array();
         
          for (var i = 0; i < aB.length; i++) {
         
               var abName = aB.name;
         
               outFiles.push(File(dF.fsName + '/' + baseName + '_' + abName + '.ai')); //changed '-' to '_'
         
          }
         
          var aiOpts = new IllustratorSaveOptions();
         
          //aiOpts.compatability = Compatability.ILLUSTRATOR13;
          aiOpts.pdfCompatible = true;
          aiOpts.saveMultipleArtboards = true;
         
          //************************************ added 2 lines
          var abRange = "1-"+aB.length;
          aiOpts.artboardRange = abRange;
          //************************************
         
          var saveFile = File(dF.fsName + '/' + docName);
         
          docRef.saveAs(saveFile, aiOpts);
         
          renameFiles(outFiles);
     }
}

artboardsToPDFs();


function renameFiles(fL) {

     for (var i = 0; i < fL.length; i++) {
         
          if (fL.exists) {
    
               fL.rename(fL.name.replace('_','-')); // swapped dash with underscore
    
               fL.rename(fL.name.replace(/\.ai$/,'\.pdf'));
              
          }
     }
}
Translate
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
Community Expert ,
Feb 08, 2011 Feb 08, 2011

oops!! I took a little too long to compose the msg, above post Z-Order should have been # 40

Translate
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 08, 2011 Feb 08, 2011

Is there a way to rename a file in a directory to a name of a file that already exists in that directory? Basically name the new file and delete the old pdf that has the same name?

Right now I'm getting ai files that can't be renamed to PDF upon export because the pdf file name already exists in that directory.  Once I get this workaround solved, I think I'll be home free...

Thoughts?

Translate
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 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 = File(dir.fsName + '/' + reName);                                if (t.exists) t.remove();                      f.rename(reName);                           }      } }

Translate
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 08, 2011 Feb 08, 2011

Mark - thank you so much.  Your help on this has been incredible.  Works perfectly.

Translate
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
Community Expert ,
Jan 31, 2011 Jan 31, 2011

preserveEditability here means to include an entire copy of the proprietary AI file in the PDF as well as the PDF data. It does not change the original AI file. Do you really need this?

Translate
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 ,
Jan 31, 2011 Jan 31, 2011

No I do not need the other artboards retained in the PDF, but I do need to access grouped objects in the PDF file.  What I mean is, when you do not "perserve illustrator editing capabilities", the art is flattened, masked, and grouped into an unselectable/usable format.  When you open the resulting PDF back up in Illustrator and click on an object, the whole artboard is selected (because of a group/mask I suppose).  Does that make sense?

Translate
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 20, 2011 Feb 20, 2011

Mark - do you know any reference sites or information I could look at  to learn the structure of the simple string/filepath edit that I need  to use change the location of these exported files?  Right now it's  using/creating a folder on the desktop called AI pdfs.

Thanks!

Translate
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, 2011 Feb 21, 2011

How would I specifiy the following location for the exported files to go:

S:\Graphics\Graphics Dept Internal Use\Manufacturing - Production\Regular Orders

instead of this location:

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

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

Can someone point me in the right direction on filepath syntax?

Thanks!

Translate
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 21, 2011 Feb 21, 2011

Tim you should be able to put your path sting 'quoted' in the dF variable like so…

var dF = Folder('S:\Graphics\Graphics Dept Internal Use\Manufacturing - Production\Regular Orders');

and loose the line below about creating a new folder… Im NOT sure about that colon in the path thou as I don't normally have to deal with PC paths…

Translate
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