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");
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 =
...Copy link to clipboard
Copied
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…
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I think I understand your request see if this does 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.desktop; var sF = Folder.selectDialog("Please choose where to save the PDF's…", dF); if (sF == null) return; 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 abName = aB.name; var pdfFile = File(sF.fsName + '/' + baseName + '-' + abName + '.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();
You will now be asked each time where you want to put the saved files…
Copy link to clipboard
Copied
Thank you so much. This is great. The only other thing I was hoping to do is to be able to set the (different) location in the code so I don't have to answer the question each time I run the script. The location won't change each time I run the script, it just needs to be in a different location than the ai master file. Does that make sense?
Your help is outstanding. Thank you.
Copy link to clipboard
Copied
Then this will look for a folder on your desktop called "AI PDF's" and save to that if it does NOT exist then it will re-create the folder and save into it. Should you need to it's a simple string/filepath edit to change this…
#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 pdfOpts = new PDFSaveOptions(); pdfOpts.pDFPreset = '[Press Quality]'; for (var i = 0; i < aB.length; i++) { var numb = (i+1).toString(); pdfOpts.artboardRange = numb; var abName = aB.name; var pdfFile = File(dF.fsName + '/' + baseName + '-' + abName + '.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();
Copy link to clipboard
Copied
Incredible. Thank you. For some reason all of the artboards are still in the extracted file, when opening the extracted PDF file in Illustrator. Is there a way to completely lose the other artboards on the exported PDF files so it's just the artboard we need for that file?
Copy link to clipboard
Copied
Im not sure about that. Multi-artboards are new to me… I would have expected the pageRange to have sorted that. Otherwise setting the preserve Illustrator capabilities to false 'may' do it but Im not at a mac that I can look into this right now. I will post back should I find anything…
Copy link to clipboard
Copied
Try setting the PDF to version 5 compatible. Only 6 and above have the concept of layers so a PDF 5 should have only one layer.
Copy link to clipboard
Copied
The [Press Quality] preset is set to Acrobat 5 compatible by default, which is the setting used in the script. I'm working with artboards, not layers.
Right now, the artboards exported PDF will open perfectly in adobe reader etc as just one artboard, but if you open the same PDF file in Illustrator, all of the artboards are there.
Copy link to clipboard
Copied
Insert this new line…
pdfOpts.preserveEditability = false;
after the line…
pdfOpts.pDFPreset = '[Press Quality]';
and you should be done…
Copy link to clipboard
Copied
Thanks Mark. I'm guessing it must be an issue with AI then. It would be a perfect fix, except we need to maintain AI editibilty as we are going to send the PDF files for manufacturing. Sounds like this may be as close as we can get with the tools Adobe gave us?
Copy link to clipboard
Copied
That would be my guess too… There is no document history or undos to fall back on so removing artboards would mean keep reopening the file yuk…
I do like it when you look in the guides and find…
artboards.removeAll()
//returns Nothing
Deletes all members of the artboard list. <<if you cannot remove the last one, what does this do?>>
OK, curiosity got the better of me and…
This method is not supported as document should contain at least one artboard
.removeAll()
Copy link to clipboard
Copied
Just wanted to make sure this isn't possible before I resort to something less efficient and desirable. I called Adobe and they were unable to help or even talk about scripting stuff. They said that AI CS5 doesn't have the ability to export artboards to seperate PDFs.
I told him about the script you created and how it works perfectly except that it retains ALL of the artboards when opening in Illustrator. He says he "is pretty sure" it is possible with scripting to do this, but couldn't give me any direction on how to find out more...other than to make a feature request.
Any other ideas of how to acheive this (using javascript or anything else (except apple, cause we're on windows 7)?
The option I'll have to resort to will be pretty much the same script, except to export to individual AI files (with pdf capability) instead of to PDF. Main problem with this for us, is that this "PDF compatible" ai file doesn't open on ipads, which is where the documents will be used for quality control checks in the warehouse to verify the graphics that were used at production (overseas). PDF has much broader usability in our company, but it just won't work unless I can maintain the working AI functionality of the pdf.
We're so close to having this it's just killing me...
Let me know if you have any ideas
Copy link to clipboard
Copied
Is it possible to have a script export the artboards to separate .ai files, and THEN convert all of those exported files to .PDF all in the same script?
Copy link to clipboard
Copied
on a different apporach, would saving the entire thing as PDF, then split the pages with Acrobat Pro work for your project?
http://help.adobe.com/en_US/Acrobat/9.0/Professional/WS3507E238-638A-4139-970C-EBAA153A5CCB.html
Copy link to clipboard
Copied
...nevermind...every split page still has all other pages
Copy link to clipboard
Copied
You can use Extract Pages from the Document menu in Acrobat for a multipage PDF and check the box to save the pages as seperate files.
Copy link to clipboard
Copied
Unfortunately that solution won't work because this isn't a one-time project. It's the way we will manage graphics for 11,000 products on a daily basis and the solution has to be one step. We edit an AI ai file, and then run a script to export all of the artboards (usable to our factories as a single artboard per product). We make these types of changes on a daily basis to several AI files with over 30-50 artboards each. It would be too much to manage to open/use acrobat every time we edit a master file.
I know it's possible to export each artboard to a seperate AI file, and that it's then possible to convert AI files to PDF (i think)...but does anyone know if this can all happen with one script?
Copy link to clipboard
Copied
it should be possible,
Are you concerned with file size? if you go this route all the individual arboards will still contain all the data (hence size) from the original file.
Edit: not sure anymore about the file size, Illustrator is acting up, maybe not the "whole" data but individual artboards are still pretty close to original with all artboards.
Edit 2: Saving as Illustrator EPS first will in fact separate the artboards for good.
Message was edited by: CarlosCanto
Copy link to clipboard
Copied
But the EPS format will flatten any transparency.
Copy link to clipboard
Copied
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…
Copy link to clipboard
Copied
Here's what I learned today. If you export the artboards to separate AI files with PDF compatibility, you can simply change each file name extension from "whatever.ai" to "whatever.pdf" and walla...the .pdf file opens perfectly on ipads and pdf readers, as well as opens as a perfectly usable ai file in Illustrator.
So, if I can tweak the script Mark gave me to do exactly what it currently does (exports artboards to a certain location) except now to export the artboards to separate .ai files....then maybe find a script (VBS maybe?) that can watch the destination folder for new files and change the names of any files with the extension of ".ai" to ".pdf" I will be all set.
Sounds simple enough, but I don't know scripting very well at all. Anyone know if it is possible to have a script constantly watch a directory for new/updated files on a windows machine and change the filenames from .ai to .pdf when new ai files are placed in that folder?
Also, what information would I need to change in Marks script to operate exactly the same, except now export to separate .ai file instead?
Thanks so much everyone!
Copy link to clipboard
Copied
I think the problem is the same which ever way you look at this… Illustartor does not have a document.revert() to saved, any workable level of undo()s or a history to which you can restore to a given state. Once you have removed the undesired artboards and kept the one required it does not matter what file format you save to because you will have to reopen the file to deal with the next artboard and so on. For each file's artboard you are going to have to open the file again… Whilst this is a scriptable repetitive process it is going to take considerably longer to perform. Are the number of artboards in the PDF that critical?
Actually I take that back… Artboards hum… 'junk' there is no association with them and their contents like layers. Removing them has no relationship with the document art. Never really understood the introduction of something that I could do in layers and now I know why I'll stick to using layers… That removeAll() in the scripting guide would have been the best idea I think…
Copy link to clipboard
Copied
I think the solution is simple at this point.
Step 1 - run the script you already created (except modify it to export artboards to individual ai files instead of PDF).
Step 2 - use an "always on" script to simply rename the files in the destination folder from .ai to .pdf upon the trigger of any new file being placed in the directory/folder.
(Obviously, I have my master AI file saved with all artboards in a separate location)
The result of the export is an AI file with only one artboard that is placed in the destination directory. Simply deleting the text .ai and replacing it with .pdf in the file name results in an AI file that is openable in Acrobat reader etc. I can also open the art in Illustrator, and it doesn't have any other artboards...all layers and Illustrator groups etc are still in tact.
The only script I'll have to manually run will be the "export each artboard to separate AI file" from the master file. Then the exported files will be renamed in the destination folder automatically. (I'm having a script written at scriptlance.com to automate that task).
Does this make sense?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now