Skip to main content
Known Participant
January 30, 2011
Answered

Multiple artboards to multiple PDF's

  • January 30, 2011
  • 2 replies
  • 18423 views

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

This topic has been closed for replies.
Correct answer Muppet_Mark-QAl63s

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?


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

2 replies

Participant
March 4, 2016

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

Muppet_Mark-QAl63s
Inspiring
January 30, 2011

A few questions…

Do you want a script that works with just the active document and you are going to run 300+ times? If so then this may do…

#target illustrator function artboardsToPDFs() {            if (app.documents.length = 0) {                      reurn;                 } else {           var docRef = app.activeDocument;           var docName = docRef.name;           var baseName = docName.replace(/.ai$/,'');           var dF = docRef.path.fsName;           var aB = docRef.artboards;           var pdfOpts = new PDFSaveOptions();           pdfOpts.pDFPreset = '[Press Quality]';           for (var i = 0; i < aB.length; i++) {                      var numb = (i+1).toString();                      pdfOpts.artboardRange = numb;                      var pad = aB.length.toString().length;                                numb = zeroPad(i+1, pad);                      var pdfFile = File(dF + '/' + baseName + '_' + numb + '.pdf');                      if (!pdfFile.exists) {                                docRef.saveAs(pdfFile, pdfOpts);                           } else {                                var rPDF = confirm('File: "' + pdfFile.name + '" already exists…\rDo you wish to replace?',false);                                if (rPDF) {                                               docRef.saveAs(pdfFile, pdfOpts);                                               } else {                                               continue;                                               }                }           }      } } artboardsToPDFs(); function zeroPad(n, p) {         var t = n.toString();      while (t.length < p) {t = '0' + t};         return t;       }

Do you want to pick a folder of all the illustrator files? If this is the case I would need more info and it would take longer…

Known Participant
January 30, 2011

Mark,

Thank you so much.  This is almost perfect for what I need.  Let me start by answering your questions.  Yes, I just need a script that I can run for each master ai file (300+) and I will run the script every time I edit the master ai file.  Just needs to run on the active document.  It's how we will maintain our graphics for our 10,000 product skus.

An example of our item number (screen printing products) set up is 102-11 or 102-58 where the first 3 digits represents a certain group of logos and the number after the hyphen is the specific product line the logo group is applied to.  Our master ai files are named with the first 3 digits (logo group),  the above example's current file name is 102.ai.  Within that file we have about 50 product lines that each have a 2 digit product number as the name of each artboard.  My hope is that i'll be able to edit the master ai file designs and export a separate PDF with the full item number so the exported filename would be 102-11.pdf  or 102-58.pdf

Right now the script is exporting as 102_(artboard number, not artboard name).pdf  (looks like102_01.pdf)  as opposed to 102-11.pdf

Also, is there away to code a different (specific) destination for the exported pdf files, other than the location where the master ai file is located?  I'd like to put that specific folder/destination in the code so we wouldn't have to select a location while running the script.  For files that need to be exported to another location, I'd just make another version of the entire script with other location coded into it.

Not sure if I'm making sense, so please let me know if not.  Are the above options possible?

Your help already has blown me away.  I can't thank you enough.

Muppet_Mark-QAl63s
Inspiring
February 4, 2011

But the EPS format will flatten any transparency.


The only other way I could think of doing this was to dupe the active artboard's contents to a new temporary document, save as, then close… But I have not had the time to try it out just yet…