Export Illustrator Layers and/or Artboards as PNGs and PDFs

Over the last year or so, I’ve cobbled together a couple Illustrator scripts that export multiple artboards in an Illustrator document as PNG files, and export multiple layers as PNG files. (See my previous blog posts here and here.) I’d been meaning to merge them into one script, but had never quite gotten around to it until Khoi tweeted that he was looking for a script that did just that, but to PDF format.

So, a couple train rides later, I’ve finally combined the two scripts into a single one with a couple more added features: you can choose to export as PDFs in addition to PNGs, and you can also export the product of artboards and layers.

To use the script, download MultiExporter.jsx and put in your Illustrator scripts folder (usually in Applications/Adobe Illustrator/Presets/Scripts/). Restart Illustrator, and run the script by going to “File > Scripts > MultiExporter”.

A few notes:

  • You can choose whether you want to export all the artboards in the document with the currently visible layers showing, or if you want to export files for each of the layers in a document on the currently active artboard, or if you want to export a combination of all the artboards multiplied by all the layers.
  • Files are named based on their layer name. It only exports layers where their name has been changed from the default “Layer 1″, “Layer 2″ or “Artboard 1”, “Artboard 2”, etc.
  • If you put a minus sign (-) in front of a layer name or artboard name, it will skip that layer or artboard. (Useful for when you no longer decide you like a particular mockup, but don’t want to delete it from the master Illustrator document.)
  • For layers only: If you put a plus sign (+) in front of a layer name, that layer will always be visible. Useful for if you want to have a layer that always appears in the background of each exported image.
  • It stores its settings in a nonvisible, nonprinting layer named “nyt_exporter_info”
  • It has an option for transparency, and lets you choose between PNG8, PNG24 and PDF.

You can try it out on the sample file artboard-layer-test.ai.

The sample file contains artwork for buttons on three artboards — “Red”, “Blue” and “-Green” — and has seven layers.

  • If you run the script and choose “Export Artboards (with currently visible layers)” it will generate two files: Red.png and Blue.png that include whatever layers are currently showing at the time you run the script. (It skips the “-Green” artboard because the artboard name begins with a minus sign.
  • If you chose “Export Layers (on currently selected artboard)” it will generate two files: Play.png and Pause.png. The “+Button” and “+Gradient” layers will appear in the background of both exported files, and it will skip the “-Pause 2″ and “Layer 5″ layers.
  • And if you choose the “Artboard + Layers”, it will do a combination of the two other options and generate four files: Red-Play.png, Red-Pause.png, Blue-Play.png and Blue-Pause.png.

Try it out, and leave a note in the comments if you have any problems or suggestions.

194 comments on “Export Illustrator Layers and/or Artboards as PNGs and PDFs

  1. erik

    Wondering what the default PDF preset is when they get exported, and is there a way to alter this?

    I believe this needs to be added when exporting:

    options.PDFPresetsList = someStringValue;

    Could this be a string with spaces? Do I need to add quotes to contain the string? Not extremely versed in javascript, please help if you have time. Thanks so much!

  2. alex

    thanks for helping the infography world getting better .. and my hair as i am pulling them from the beginning of the day cause the native export png function doesnt work properly

  3. Bart-Jan Dekker

    Hi, I’m using CS4 on Windows and get the following error: “Error 21: undefined is not an object. Line 533 (etc.)”
    I’m guessing this script doesn’t work on CS4?

  4. Mark J.

    When I run the script, I get no messages, no errors, and no output files. However, I do see this in the Console log:

    ================
    Adobe Illustrator: CFURLCreateWithString was passed this invalid URL string: ‘/System/Library/Frameworks/’ (a file system path instead of an URL string). The URL created will not work with most file URL functions. CFURLCreateWithFileSystemPath or CFURLCreateWithFileSystemPathRelativeToBase should be used instead.
    ================

  5. Jonny

    It kind of works but it exports layers cropped i.e. the relative placing within an image is lost. If a layer is less wide than the total width of the image (I should say art board?), the output layers are of different sizes. Having the same “canvas” size of all output images would help a lot.

  6. mericson Post author

    The layers should all be sized exactly the same as the artboard they are on. What version of Illustrator are you using? And if you want to send me the file — matte at nytimes dot com — I’d be glad to take a look.

  7. mericson Post author

    What version of Illustrator are you using? And have you tried restarting Illustrator fresh? (Sometimes I’ve seen problems where the scripting engine gets a bit funky if Illustrator has been left running for a long time.)

  8. Daren

    When I click on the download link above, it opens plain text in the same window. Am I to copy and paste this into a plain text document, then save with .jsx extension and place in the directory as you mention? Just want to be sure I get the process down right before I try.

    Thanks!

  9. Marcelo

    Hi Matt,

    great to find this sort of stuff online..

    I was wondering if you can make the same but exporting different “plates” such as let’s say a pdf file for cyan, another for magenta and so on..

    Thanks a lot!
    Marcelo

  10. SLV

    Hi, I’ve been looking for something like this forever so thanks for creating it! I have an illustrator file with 120+ layers that I need to export to PDFs and this seems to be exactly what I need. However, I’m using Illustrator CS3 and when I try to run it I get the following error:

    Error 21: undefied is not an object.
    Line42
    -> this.num_artboards = docRef.artboards.length;

    Help?

  11. mericson Post author

    @Daren: Yep copy the script into a text file, than save with a .jsx extension in Applications/Adobe Illustrator/Presets/Scripts/

  12. mericson Post author

    @SLV: The script only work with CS5 and up, since CS5 is the first version that supports named artboards. If you’re just looking to do layers, you can try this script instead, which I think might work with CS3 (But I don’t have any old versions of Illustrator handy, so I can’t test.)

  13. mericson Post author

    @Marcelo: Due to the way the script works, I think it would be much more difficult to make it export plates, so I don’t have any plans for that now.

  14. Jacob

    How could I export as Illustrator 9 EPS, Need it for a current project unfortunately. Thanks in advance!

  15. Kelly

    This worked beautifully! A million thank yous for cutting a job to probably a thousandth of the time it would have taken me.

  16. Jennifer

    You can also just open the page > right click > save page as and it will save it as a jsx file. No need to copy and paste into a text file!

  17. Doc4

    You should mention that there is a slight delay when saving files with image heavy layers. I almost didn’t think it was working. Please note that I made all layers visible and unlocked them as well.

    Fantastic addition to Illustrator CS6, I can’t thank you enough.

  18. Russ

    Howdy,

    Thanks for the script. I just tried using it and got the following error message:

    -> bplist00—_WebMainResource

    Any idea what I did wrong?

    Thanks

  19. Brian

    Thank you for freely sharing and explaining your code! This will save me a lot of time in the future, you’re the man!

  20. Ken

    hi, can anyone explain a little bit more about the work around of the script? i’m not sure if it’s working as there’s nothing happened, even error message not showing. i tried on CS5 and CS6 but still no luck. thanks everyone!

  21. vlsb

    Hi, To get it to work in CS4, I just removed the bit about artboard names (line 533). Any chance of adding layers to one multi-page pdf file functionality?

  22. kate

    I am using CS6, does this script work in this version? I am having a similar error to another user where I run the script and seemingly nothing happens. Help? Seems like this could really be a lifesaver. I wonder why Adobe hasn’t figured this one out yet! not all files can be created in photoshop or fireworks 🙂

  23. claire

    Hi there.
    Can you tell me if this works on CS6?
    I have downloaded the script and I can create a PDF but It skips the Export Panel. All of the layers that I have selected to export are dumped onto one page.

    I would LOVE to get this amazing script to work 🙂

  24. Pingback: Creating proofs from existing Adobe Illustrator documents - ProofHQ

  25. Alyssa

    I am madly in love with you right now for making this!! You just saved me hours of future work. Thank you!!!

  26. kFish

    I’m trying to launch your script from my desktop in CS5, the “Export Artboards” window appears, I either get “Will export 0 Layers 0 Artboards or it only exports the selected art board from one of the other options.
    What am I doing wrong with Layers and Artboards (I let Ai name them) and is it ok that all artwork is flattened on one layer? Does each Artboard require a separate Layer?

  27. Steve

    Thanks! Saving as PDF’s works great with CS6.

    Is there a way to change the resolution of the exported PDF’s? Each of my exported layers is 15MB and I don’t want to have to open Acrobat to downsample each layer. – Cheers!

  28. Jesper

    Hello, I just came across this and I just wanted to say THANK YOU. I am working on a huge mobile app project and am creating a ton of buttons, icons and what not. I can not tell how much time this have saved me. Thanks again.

  29. Abhishek

    First of all, this is fabulous. Thanks.

    I am using Illustrator CS6 and the usual export to png24 option gives the user the choice to change the resolution in ppi. Would it be possible for you to include that option?

    Another option I am looking for is to have the script export each of the say 3 artboards as filename_1, filename_2, filename_3 by default (without requiring any change in the names of the artboards or addition for + and – symbols)

    Any help here would also be massively helpful to the design community. Please see if you can find the time for this 🙂

  30. Jordan

    Hey all,

    Thought I’d add something here. This script is wonderful and just saved me about 2 hours worth of work. For that, thank you Matthew.

    However, I had a problem that I was trying to figure out that I think others may have as well. With the newer versions of Illustrator, when exporting images, it defaults to the size of the artboard. I needed each individual image to be saved at the image size (rather than the size of the artboard).

    If anyone is reading this and needs to export their layers/artboards as the size of the image itself, instead of the size of the artboard, simply open the script, search for “options.artBoardClipping”. Change it from “true” to “false”. This option is under PNG 8, PNG 24, and JPG options.

    Hope this helps out.

  31. Chris Forrester

    Awesome!
    Very handy for importing ai layers into After Effects as PNGs…Sometime you can’t trust designers from changing all their layer names after an import!

    Thank you for this 🙂

  32. Rick

    Great script! I’ve been using it regularly for weeks now and I’ve never had a problem, however, I introduced a friend to this script and it worked for her… without PNG transparency. It’s really weird, she sent me the file and I had no problem exporting the layers as PNG with transparency. I made sure she had the transparency box checked but it still didn’t work for her. Any advice? Thanks again for writing this script!

  33. Alex

    Wonderful script… but I’m having difficulty getting it to run correctly in Illustrator CS5.5. An error to the tune of “Could not complete this operation. An unknown error has occurred”? Not too sure what I might be doing wrong. Does anyone have an idea?

  34. get hyper

    This script is brilliant. But when saving as EPS, all the layers are saved as hidden layers. Is there a way to make it so the new EPS only contains the each layer without all the other hidden layers?

  35. Kaitlin

    I was having the same problem as @SLVE n CS6 where I would receive this message:

    Error 21: undefied is not an object.
    Line42
    -> this.num_artboards = docRef.artboards.length;

    It’s because my file wasn’t open first. Do all the instructions above, download the script, put it in your ai script folder, close illustrator, open it, open your file you want to export, THEN open the script: file > scripts > multiexporter

    Hope that helps fellow CS6ers!

Leave a Reply

Your email address will not be published. Required fields are marked *