How to Use Adobe Illustrator Variable Data with XML

UPDATE: There’s now a much better way to use variable data with Illustrator. It’s achieved using the VariableImporter script, and you can view my newer Adobe Illustrator Variable Data tutorial here!

SUPER-DUPER Update: I’ve completed a 2.5 hour course on how to use the NEW Variable Importer 8.0 script, and it’s available on Lynda.com! Click to check out more info on the Adobe Illustrator Variable Data Lynda.com course!

And now back to our regularly scheduled blog post…


If you’ve ever had to use Adobe Illustrator to set up multiple variations of a single file, then using the “Variable Data” feature could save you a lot of time. It’s not very intuitive to set up, though, so I made up this tutorial. The companion video I created for this post is pretty comprehensive, but in case you’d rather read, I wrote an extensive description as well.

Illustrator Variable Data Steps

First, here’s a quick list of the steps we’ll take to make this work

This seems like a lot to do, but you’ll burn through these steps pretty quickly once you get the hang of it.

Set up Illustrator for variable data

If you’re like me, you already set up one of the files you need, and then suddenly realized you have 50 more of these to do.

Checking my screenshot below, I have a file set up with a number of variables. There’s a linked placeholder graphic for images, and the rest are all text objects.

Adobe Illustrator variable Data setup

Honestly, it doesn’t matter what text is in there right now. It could all be gibberish, as long as you have everything placed and styled the way you want. Any text will be replaced anyway.

The only text issue you need to clear up is to make sure none of the text is grouped. You can’t assign variables to grouped text, so be sure to ungroup everything before attempting it.

For your graphic, make sure the file is LINKED and not EMBEDDED. If it’s linked, you’ll see the “X” through the graphic as in my screenshot. If it’s already embedded, re-import it again and this time make sure the “Link” checkbox is checked before you click the “Place” button as shown below.

Adobe Illustrator variable Data  place image

Also, to keep this “template” file working, perform as “Save As…” and make sure the “Include Linked Files” checkbox is unchecked. Once you embed an image, it will stop working as a variable.

Adobe Illustrator variable Data linked images

If you have a graphic in your design, then you’ll need to get the path to the graphic for the variables to work. To do this open up the Variables palette by going to Window > Variables from the top menu.

Once the variable palette is open, click your linked graphic, then click the “Make Linked File Dynamic” button at the bottom of the Variables palette.

You should now see one variable show up in your Variables palette (it probably says “Variable1”), as in my screenshot below.

Adobe Illustrator variable Data test image

At this point, click the “Capture Data Set” button to the left of the Data Sets field, then click the flyout menu on the side of the Variables palette and choose “Save Variable Library…”. This will be an XML file with the correct formatting for Illustrator. Save this file wherever you want and then open it in a text editor such as Notepad++ on Windows, TextEdit on the Mac, or I use TextWrangler myself.

The only thing you need from this file is the path to your image. Look for the first instance of “Variable1” and you should find the file path. On the Mac it starts with “file:////Volumes” and will list the entire path to your file. Make sure all of your graphics are in this directory.

Adobe Illustrator variable Data  image path

Once you have this, go back to your Illustrator file and delete the variable from the Variables palette. We don’t want that to exist when we import our final XML file.

Now your Illustrator file should be ready, we just need to create our XML file with the actual data we’re going to use.

Set up Excel/CSV file data

The most important thing about setting up your Excel file is that the first column should be named “Dataset”.

In my screenshot below, you can see how the columns are named across the top row. Those names are going to end up being the names of my variables in Illustrator. The only one that’s really important is the Dataset, the rest could be named anything as long as you know which parts of your design they correspond to.

Adobe Illustrator variable Data spreadsheet

In the Dataset column, I simply copied the “Name” column into it. Each Dataset needs to have a unique name, or else you’ll get an error on import back into Illustrator. You could easily use numbers here, too. I tend to use something more descriptive because it’s easier to find that specific dataset in Illustrator, and also because I append the dataset name onto the end of the file at final export time, and that helps to easily identify them.

If you check my “Image” column on the right, you can see how the path we collected earlier is used for each file. That’s really the most difficult part of setting up your spreadsheet file, assuming you’re using images, of course.

Once you have all your information plugged into the file, you can either save it as a .csv (comma separated value) file, or just leave it as .xls (Excel), or in my case, .ods (Open Document Spreadhseet) since I’m using NeoOffice.

Convert spreadsheet cells into XML using an online converter

Unfortunately, Illustrator can’t recognize any of the usual spreadsheet formats. It will only recognize XML, so we now have to turn this spreadsheet into an XML file.

Luckily, there is an online CSV-AiXML Converter created by João Faraco.

Adobe Illustrator variable Data online converter

All you need to do here is copy your cells from your spreadsheet and paste them right into the top box on the page (see screenshot above). The bottom box will immediately become populated with the xml output you need for Illustrator. If you opened your .csv file in a text editor, you could also copy your comma separated values into the top box, but honestly I never bother to do that, I just copy right from the spreadsheet cells, themselves.

Once the bottom box has the code in it, copy everything from there and paste it into your text editor. If you’re using TextEdit on the Mac, make sure it is in plain text mode (Format > Make Plain Text). RTF mode could introduce errors.

Save this file and make sure to add the “.xml” extension at the end, or else Illustrator won’t be able to import it.

Fix Image issues in XML file using a text editor

If you used images, there are a couple of changes to make.

First change: the XML converter only deals with text, so your image column will be coded as a text variable. It will look something like this:

<variable varName="Image" trait="textcontent" category="&ns_flows;"></variable>

We need to change that so it looks like this:

<variable varName="Image" trait="fileref" category="&ns_vars;"></variable>

Second change: If you check the Image tags which contain the file paths, you’ll see that the paths are surrounded by paragraph tags as if they were text:

<Image><p>file:////Volumes/My Hard Drive/Illustrator Variable Data/Tiff/captain-america.tif
</p></Image>

This needs to be removed, so depending on the number of items you have you’ll either have to delete them manually, or do a find and replace to get rid of them. The image tags should look similar to this when they’re correct:

<Image>file:////Volumes/My Hard Drive/Illustrator Variable Data/Tiff/captain-america.tif
</Image>

The below screenshot is the “grep” search I use in TextWrangler to remove the paragraph tags from the Image variable.

Adobe Illustrator variable Data grep

Grep is a pattern matching program that comes in handy for search and replace functions.

The top “search” code in the screenshot is:

<Image>\r(.*)<p>(.*)</p>\r(.*)</Image>

This tells TextWrangler to search for the “Image” tag, followed by a return character “\r”, then capture “(.*)” any characters that come before the first <p> tag. Next, it captures whatever characters are in between the paragraph tags, then searches for the closing paragraph tag followed by a return character. The last bit captures whatever characters come before the closing “Image” tag, along with that tag itself.

The bottom “replace” code is simpler:

<Image>\r\1\2\r\3</Image>

This replaces the “Image” tag, along with that first return character, then the “\1\2” simply drops back in the text that was captured by the first and second search captures, then adds another return character, drops in the text from the third search capture “\3”, and finally wraps it up with the closing “Image” tag.

Grep might seem like a lot to handle right now, especially if you’re just trying to get a job out the door, but it’s a very powerful tool to have in your arsenal if you can spare a little time to bone up on it.

You don’t have to search and replace the paragraph tags this way, but if you don’t make these changes, Illustrator will fail to see that variable as an image link, and treat it as text instead. This will likely result in either an error, or nothing happening at all.

Once you’ve done this, your file should be good to go for importing into Illustrator as a variable library.

Load XML file into Illustrator

Now, back to our Illustrator file, we need to import our newly created XML file.

If you didn’t delete our test image variable from before, make sure to do so now. Then, after the Variables palette is clear again, open the flyout menu on the side of the palette and choose “Load Variable Library…”, then select your XML file.

You should now see all of your variables appear in the Variables palette. They should be the same names as the column headers from your spreadsheet.

Checking my screenshot below will show all my variables loaded into the palette.

Adobe Illustrator variable Data load variables

One oddity about this method is that you’ll see a variable called “Dataset” appear in your palette. This doesn’t harm anything, but it has no purpose there, so you might as well delete it.

Assign variables to our placed text and graphics.

After that, it’s time to match up (bind) our variables with their corresponding elements on the page.

To do this, first select your design element, click the variable it belongs to in the Variables palette, then click the “Make Text Dynamic” button at the bottom of the Variables palette.

So in my example file I would first select the “NAME” text object in my design, then select the “Name” variable in the Variables palette, and with both selected, I would click the “Make Text Dynamic” button on the bottom left of the palette. Do this for all of your variables. For your image(s), the “Make Text Dynamic” button becomes “Make Linked File Dynamic”.

When you’re finished, it may appear as if nothing has changed. To see your variables in action, click the Data Set dropdown at the top of the Variables palette. You should see a list with the names of all of your datasets showing. Choose one, then you can click the arrows to the right of the field and you should see your variables change to the new information each time. When you reach the end it should cycle back around to the beginning.

WARNING: As far as I can tell, you CANNOT get the linked variable images feature to work if you’re using Illustrator CS5 on the Mac. I tried reformatting the XML many different ways but all to no avail. I saw others reporting the same problem, but with no solution. Illustrator CS5 Mac is my main version, but I was able to verify that it does work perfectly on Illustrator CS6 and Illustrator CC. If you’re using Illustrator CS5 and you need Illustrator variable images to work, you may have no other choice but to upgrade (or downgrade).

Create export action

Now that you have the variables loaded in and working, you’re going to have to output these to separate files at some point. This is accomplished by using an export action.

If it’s not already open, select “Window > Actions” from the top menu. Select “New Action…” from the right flyout menu, or click the New Action button on the bottom of the Actions palette.

In the window that appears, you can name the action something like “Save EPS” or Save AI” or anything that helps you remember what it does.

Once you click the “Record” button in that window, the action will begin recording. From this point, do a “Save As…”, and then choose your desired format and location. Don’t worry about what you name the file at this point.

When the file is saved, make sure to click the “Stop” button at the bottom of the Actions palette. You now have a complete action you can use to export all of the datasets.

Use export action in Batch process to export all files.

It would take a long time to switch datasets and export each time, so from here we’ll use the “batch” feature to run that action on every one of the datasets.

To start, open the flyout menu on the Actions palette and choose “Batch…” from all the way at the bottom.

In the window that pops up, make sure your action is chosen in the “Action” dropdown. Set the “Source” to “Data Sets”, and choose a folder in the “Destination” area (you can choose a different folder than the one you saved to in the action itself).

Adobe Illustrator variable Data batch action

On the right of the “Destination” area is where I set my File Name to use “File + Data Set name”. You don’t have to use that option, it’s just the one I prefer.

As soon as you click the OK button, Illustrator will begin switching through all the data sets and saving them out according to your action. Depending on the speed of your computer and the number of records this might take several minutes. It will definitely be faster than doing it by hand, though.

At this point you’re essentially finished, you have all your files exported and ready to go. Obviously you should take a quick look at all the files using bridge and make sure no errors jump out at you, but basically it should be all good.

(Optional) Use Bridge or another action to add file extensions to exported files.

One strange caveat about Illustrator’s batch process is that for some reason, it refuses to save the file extension.

This may not be a show-stopper for some, but in my case the Onyx Rip I was using refused to see the files if they didn’t have a proper “.eps” extension.

Obviously you don’t want to add “.eps” to 50 files by hand using the Finder on the Mac, so a better way to do this is to use Bridge to add the file extension by running a “Batch Rename…” from the “Tools” menu at the top. Make sure all the files are selected before you run it, though.

In the Batch Rename window, choose “New Extension” from the dropdown in the “New Filenames” section, then type in your desired extension in the field that appears. When you click the “Rename” button, Bridge should quickly run through your files and add the extension.

Adobe Illustrator variable Data rename extension

What I do myself, though, is simply drop the files onto an Applescript action I created using the Automator application on the Mac. I made a few different actions – separate ones for .ai, .eps, .pdf, .jpg, .png and .tif. I’ll include the download links here for those of you on the Mac (sorry, I’m not sure of a comparable way to make actions like this on Windows).

Click here to download the extension adder Applescripts

The Wrap Up

Ok, now you should be all set and ready to roll with the Illustrator Variable Data feature.

I initially wrote this piece because the info is so sparse on Illustrator that I figured any little bit that pops up in Google might help somebody.

Usually, when you find any info on this, the inevitable response is “Do you have access to InDesign?” Use Data Merge in InDesign, instead.”

Those people are right, of course. InDesign’s Data Merge feature is superior to Illustrator’s Variable Data in pretty much every way. The number one best feature is that InDesign’s Data Merge recognizes a plain .csv file, so no need for the XML acrobatics we had to do for Illustrator. Plus, no annoying CS5 bug for images. And unlike Illustrator, there’s a vast wealth of information out there on Data Merge. Illustrator tutorials can be hard to come by. Not to mention that at least InDesign can manage to save the file extension when you save out your files.

Additionally, InDesign’s Data Merge is smart enough to create multiple records on the same page, whereas Illustrator can’t do that easily, if at all.

For example, if I wanted an 11″ x 17″ sheet with twelve of my cards on it, InDesign would create cards with Superman all the way through Cyclops on that page, then kick the rest to the next page and set those up for me.

In Illustrator you can’t do this in a very efficient manner, if at all. It can possibly be done, but you’d end up expending more effort, when this whole variable data thing is supposed to actually spare you from tedious, repetitive work. So the bottom line is – if you’ve got a lot of variable data to deal with, do it in InDesign if you possibly can, and only rely on Illustrator’s Variable Data if you absolutely have to.

Here’s a bit of other Illustrator Variable Data reading just in case you want to see some other methods. I got most of my info from these sources:

With that said, I’m outta here for now, leave me any questions in the comments and I’ll try to help out if I can. Good luck and I’ll see you guys next time!

Previous » Next »

21 thoughts on “How to Use Adobe Illustrator Variable Data with XML

    1. Thanks Maurice. I think the people who need this are a small minority of Illustrator users, but when you need it…you REALLY need it, lol.

      I’ve used Inkscape a number of times. It’s a very high-quality open source program. I know a lot of Blender users who swear by it. When you think about it, it’s awesome how you can use Gimp and Inkscape to replace Photoshop and Illustrator and not spend a dime.

      I think there was an open source page-layout program that could fill in for InDesign, too, but I can’t remember what it is now…

  1. This looks super useful! You’re right, when you need it, you REALLY need it. Going to run through it in the next few days so may be back! Thanks JG.

    1. Yeah, I hear ya Zak!

      Definitely let me know if you need any help. Illustrator is kind of finicky about variable data so if you run into trouble just hit me up. Good luck!

        1. WOW! Thanks so much JG! Finally got round to using it on 98 different images and worked like a treat. Not too confusing once you get your head round it but wouldn’t have been able to do it without your video.

          Many thanks!

          Zak

          1. That’s great news, Zak! I’m glad that worked out for you, anything to make production go faster, right?

            Thanks for letting me know how your project got on, and all the best!

  2. Thank you so much, it work perfect in cs3, I use it for build bingo cards with 20 variables and work perfect, Photoshop couldn´t handle it.

  3. Thank you SO much for this tutorial! I was pulling my hair out hoping this was possible. I had to create 500 odd unique username and password cards for a training session and this worked perfectly. Thanks for creating the video as well… Seriously giving you a standing ovation!

    1. Forgive my super late reply Anna, but I’m glad this helped you out – I know how tough it can be to get this working so I’m happy you got your cards working. Thanks for commenting!

  4. Hey John ! Great video, and thanks for referencing my converter :D It’s not perfect, but it’s great to see it being used.
    I must credit Shan Carter for building the base data converter. He actually merged my branch with his original Mr. Data Converter (http://shancarter.github.io/mr-data-converter/), so now you can also convert to AiXML there too, and take advantage of the extra options it has.

    1. Hey João, thanks for dropping in here! I was happy to reference your converter because it saved me a ton of time and frustration in this process.

      Thanks for the information on the updated convertor, I’m sure those looking to make this work will find it extremely helpful.

      All the best, man!

  5. Hey! Stumbled on your youtube on this today. It was a pretty great run down on how to work with that tool. I’m a little amazed that it gets over looked as much as it does but I was just as guilty.

    I was curious if you’d experimented with using that in conjunction with a document that has multiple artboards. I’ve been playing with some tricks to make my life easier with those but this process feels a little like you’d really have to start with the one artboard/one page layout then after you exported I suppose go from there.

    I’m eager to get some time to do some testing but thought I’d ask if you had any thoughts on it too.

    Thanks for the tut. Very useful and opens up some ideas to adapt.

    1. Hey there!

      you know I actually tried experimenting with multiple artboards, but without much success.

      Sure you can put the variable wherever you want, but the variable data feature doesn’t really recognize them per se.

      I think you’d have to look into scripting to be able to target specific artboards. So your initial gut feeling is pretty much correct regarding this.

      Glad you were able to get something out of this and thanks for stopping in!

  6. Thanks so much for this awesome tutorial!

    If you run into issues with Illustrator telling you your file is not valid, there are a couple of things it could be (the Illustrator error message is NOT HELPFUL).

    First, make sure any values in your first column (dataset) are unique. You can’t have two lines with the same dataset name.

    Also, special characters (&, ‘, and so on) in the dataset name (and maybe elsewhere) will make Illustrator cry (and reject your file). :-(

    I really wanted to add a line break in my data but Illustrator rejected both the entity and a CDATA block. So I gave up and just created two text boxes …

    Hope this helps!

  7. Sadly the generator doesnt work fro me anymore, something about the code returns error on illustrator as it cannot load. I end up having to:
    1) make Dataset in illustrator
    2) save dataset from illustrator as xml
    3) copy excel content
    4) past excel content in generator website you provided
    5) copy that text, paste in textedit
    6) copy the GUTS of that file
    7) Open the xml file i generated from ILLUSTRATOR
    8) replace the guts from there with new guts…

    thats the only way I could get it to work =( the code straight from the generator would not get recognized by illustrator.

    1. Hi Kevin, I really hate to hear that it’s not working anymore.

      Can you tell me which version of Illustrator you’re using? I’d like to test it out myself.

      Also, did you try the link that João (the creator of that convertor) posted a few comments above: http://shancarter.github.io/mr-data-converter/

      choose the output as “XML – Illustrator” and see if that helps out.

Comments are closed.