Place an SVG into an illustrator document through Javascript(Extendscript)

Hi,
I'm trying to place an svg in illustrator using extendscript. Here's basically what I'm doing
var doc = app.documents.add(); var p = doc.placedItems.add(); p.file = new File(svgfilepath);
This fails with the error
File is in a format that cannot be placed
I am able to place the same file manually using File > Place. Am I missing some thing? Need help!
[SO Link]

Hi, try the following:
// Reference: https://forums.adobe.com/thread/1722322
// Assumes you have an open Illustrator document
// and an SVG file on your desktop named: testSVG.svg
// Basic Example:
// Tested and worked in Illustrator CS5 / OS X
var doc = app.activeDocument;
var svgFile = File(Folder.desktop + '/testSVG.svg');
doc.groupItems.createFromFile(svgFile);
Tell Jongware at "SO" hello, and that he is right about the Illustrator JS Team. ;-) Also for future reference, we have an Illustrator Scripting forum here.

Similar Messages

  • Can you export images which have been pasted into an Illustrator document as separate files?

    I have a multi-page Illustrator document (over 50 artboards) which contains lots of images that are all saved within the document (not linked in from seperate files) and all the images need to be exported as separate image files (similar to when you package a file in Indesign). The problem is the files are not linked, they are all saved within the document.
    Want to avoid having to copy + paste every image into a new document in Photoshop and save individually as this will take forever.

    Save the document as a PDF and Open in Photoshop. Select only the Images in the Open dialog and proceed from there.

  • Batch combine files into one illustrator document - how to open target document?

    I am making a script which will:
    1) Open a folder of Illustrator files
    2) Open each file in the folder (these files are called the source files)
    3) Select all the contents of the source file
    4) Copy the contents of the source file
    5) Paste these contents into a target file as a new layer
    6) Ensure the new layer has the same name as the old source file
    However, I don't know how to tell Illustrator where my target file is. How can I do this?
    Also, when I paste, how can I turn off paste rembers layers. (So the layers get pasted into the new layer that has the same name as the old document).
    Here is my code:
    // JavaScript Document
    //Set up vairaibles
    var destDoc, sourceDoc, sourceFolder;
    // Select the source folder.
    sourceFolder = Folder.selectDialog('Select the folder with Illustrator files that you want to mere into one', '~');
    // If a valid folder is selected
    if (sourceFolder != null) {
              files = new Array();
              // Get all files matching the pattern
              files = sourceFolder.getFiles();
              if (files.length > 0) {
                        // Get the destination to save the files
                        destDoc = document.selectDialog('Select the final saved document', '~');
                        for (i = 0; i < files.length; i++) {
                                  sourceDoc = app.open(files[i]); // returns the document object
                                  var myLayers = sourceDoc.layers; // All layers in Active Document
                                  //Go through all layers of source document and copy artwork
                                  for (i = 0; i < myLayers.length; i++) {
                                            myLayers[i].hasSelectedArtwork = true;
                                  with(sourceDoc) {
                                            var count = pageItems.length;
                                            for (var i = 0; i < count; i++) {
                                                      pageItems[i].selected = true;
                                            redraw();
                                            copy();
                                            for (var i = 0; i < count; i++) {
                                                      pageItems[i].selected = false;
                                  //Create a new title variable that has the title of the source document
                                  var title = sourceDoc.name;
                                  var title = title.substring(0, title.length - 4); //(remove extension from name)
                                  //Close the Source Document
                                  sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
                                  //Open the Destination Document and create a new layer in it that is named after the title variation
                                  var newLayer = destDoc.layers.add();
                                  newLayer.name = title;
                                  //Paste into this new layer
                                  destDoc = app.paste();
              else {
                        alert('No matching files found');
    Thanks in advance for any help   
    Edit: Also, when pasting, how can I paste in place instead of just pasting.

    I have been studying this script. It is similar to what I need except it places the source files (Instead of copying & pasting them)
    http://kelsocartography.com/blog/?p=204
    I have adapted the script to my needs and it works perfectly, except it has the same problem as before: It pastes the first source file, but then it endlessly starts pasting the second source file (in a loop) and so I have to force quit.
    So my new question is, when looping through files how can you get illustrator to move on the next one?
    The original kelsocartography had this line:
    thisPlacedItem = newLayer.placedItems.add()
    thisPlacedItem.file = imageList[i];
    I belive this line is what makes Illustrator move onto the next file, but I am not sure how to adapt it to my code.
    Here is my code so far:
    function getFolder() {
              return Folder.selectDialog('Please select the folder to be imported:', Folder('~'));
    function importFolderAsLayers(selectedFolder) {
              // if a folder was selected continue with action, otherwise quit
              var myDocument;
              if (selectedFolder) {
                        myDocument = app.documents.add();
                        var firstImageLayer = true;
                        var newLayer;
                        var thisPlacedItem;
                        // create document list from files in selected folder
                        var documentList = selectedFolder.getFiles();
                        for (var i = 0; i < documentList.length; i++) {
                                  // open each document in file list
                                  if (documentList[i] instanceof File) {
                                            // get the file name
                                            var fName = documentList[i].name.toLowerCase();
                                            var sourceDoc = app.open(documentList[i]); // returns the document object
                                            var myLayers = sourceDoc.layers; // Select All layers in Active Document
                                            //Go through all layers of source document and copy artwork
                                            for (i = 0; i < myLayers.length; i++) {
                                                      myLayers[i].hasSelectedArtwork = true;
                                            with(sourceDoc) {
                                                      var count = pageItems.length;
                                                      for (var i = 0; i < count; i++) {
                                                                pageItems[i].selected = true;
                                                      redraw();
                                                      copy();
                                                      for (var i = 0; i < count; i++) {
                                                                pageItems[i].selected = false;
                                            //Create a new title variable that has the title of the source document
                                            var title = sourceDoc.name;
                                            var title = title.substring(0, title.length - 4); //(remove extension from name)
                                            //Close the Source Document
                                            // check for supported file formats
                                            if ((fName.indexOf(".eps") == -1)) {
                                                      continue;
                                            } else {
                                                      if (firstImageLayer) {
                                                                newLayer = myDocument.layers[0];
                                                                firstImageLayer = false;
                                                      } else {
                                                                newLayer = myDocument.layers.add();
                                                      // Give the layer the name of the image file
                                                      newLayer.name = fName.substring(0, fName.indexOf("."));
                                                      // Place the image on the artboard
                                                      sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
                                                      //Paste into this new layer
                                                      newLayer = app.paste();
                        if (firstImageLayer) {
                                  // alert("The action has been cancelled.");
                                  // display error message if no supported documents were found in the designated folder
                                  alert("Sorry, but the designated folder does not contain any recognized image formats.\n\nPlease choose another folder.");
                                  myDocument.close();
                                  importFolderAsLayers(getFolder());
              } else {
                        // alert("The action has been cancelled.");
                        // display error message if no supported documents were found in the designated folder
                        alert("Rerun the script and choose a folder with images.");
                        //importFolderAsLayers(getFolder());
    // Start the script off
    importFolderAsLayers(getFolder());

  • Is there a way to insert comments directly into an Illustrator document so that every time you expor

    I use Illustrator a lot to create website designs, and pepper the PDFs with comments on how everything should work. Is there a way to have those comments embedded into the AI so that I don't have to enter in the comments every time I export a PDF?

    Template are the pre-designed document in which you do the modification as per the need.
    this will give you better idea..
    http://help.adobe.com/en_US/illustrator/cs/using/WS714a382cdf7d304e7e07d0100196cbc5f-6330a .html
    So , you can create a template with the comment on it.
    when creating the new file , base it upon the template so that you have the comment already present in the Ai.

  • Adding XMP metadata into new illustrator document

    var app:Application = Illustrator.app;
    var doc:Document = app.activeDocument;
    var xmpString:String = doc.XMPString;
    var xmpMeta : XMPMeta = new XMPMeta(xmpString);                       
    var myNamespace : Namespace = new Namespace("test", "http://test.thisiscool");
    xmpMeta.myNamespace::stringName = "supercool";
    var tmp : String = xmpMeta.serialize();
    doc.XMPString = tmp;
    If I execute the above code block I end up with the following metadata inside the document:
    <rdf:Description rdf:about=""
                xmlns:ns1="http://test.thisiscool">
             <ns1:stringName>supercool</ns1:stringName>
          </rdf:Description>
    Why is the prefix defaulted to ns1 when I specified that it should be "test"?
    The documentation says you can register your own custom prefixes. But it doesn't say weather it's possible to do that programatically.  Is it?  If not, how is it done?:
    Prefixes are not stored in the data model, but only in namespace URIs. The parser collects the namespace prefixes, to be used when the same XMPMeta object is serialized after modification. For the Adobe standard namespaces, defined in the XMP Specification: Part 2, Standard Schemas, the default namespaces are stored in a global namespace registry of the library. You can also register custom prefixes for your own namespaces; if the serializer does not find a registered prefix for a certain namespace, it generates prefixes of the form "ns1", "ns2" and so on.

    The CS SDK forum is actually probably more correct, but this is probably an Illustrator scripting question.
    You might be able to add the namespace using the XMP Namespace Designer, but I'm not sure...
    Harbs

  • Can't copy image from Adobe Reader into Adobe Illustrator

    I am attempting to copy an image from a document in Adobe Reader 8 into Adobe Illustrator CS3. When I try this I get this message in Illustrator:
    "Quicktime^TM and a decompressor are needed to see this picture."
    I am running OSX 10.5.2, with Quicktime Player 7.4.1. I just purchased and registered Quicktime Pro but that has not helped.
    What I am trying to do is use the image select tool in Reader to select an illustration out of a long PDF document so just opening the PDF in Illustrator is not convenient, nor is extracting the image, saving it in another format and then importing it. Before I upgraded, I was running Illustrator 10 on MAC OS X10.3. I could use the image select tool in Adobe Reader to copy an image to the clipboard, and then paste that image into in Illustrator document. Very convenient. For some reason that no longer works with Illustrator CS3 and OS X 10.5.

    "Try opening the document in Illustrator. There will options for importing different pages etc."
    I can do that, but it is for my purposes much more convenient to do what I used to be able to do: open a document in Reader, scroll down through the document to find the image I want, select only that image (not the entire page) and then paste it into an already-open Illustrator document. Now what I have to do is 1. use Reader to find the image in the document and note the page 2. Open that page of the document in Illustrator and then 3. copy that page into the illustrator document I am working on and 4. crop to just get the image.

  • Color variation between two identical illustrator documents???

    I am trying to copy an object from one Illustrator document into another Illustrator document but it keeps changing the color and adding a small stroke around the object.  I can seem to figure out why it would be doing this????  I have check the color modes on both and they are both in CMYK.
    Any thoughts???

    Have you measured the colour?
    Do you get different readings or is it just a a contrast thing? (The "stroke" might be just an anti-aliasing artifact.)
    Sometimes your eyes can fool you.
    In this example the little grey inside squares are exactly the same colour but your eyes tell you that the left hand one is blueish and the right hand one is yellowish.

  • Can't import "Adobe Shape" generated SVG into Illustrator

    I've used Adobe Shape to create a few vector graphics that automatically sync to Creative Cloud (very cool), but when I'm in Illustrator I can't import the graphics from the library. When I drag the library item onto the canvas, nothing happens. If I double click the item, I get the message below:
    I'm dragging into an open document, and nothing happens. For what it's worth, I can place the object in Photoshop, but then I loose the vector format I'm after.

    Please use it through creative cloud library. How to get started with Creative Cloud Libraries | Adobe Creative Cloud Tutorials
    Pasting the snip from the FAQ: Adobe Shape Help | Adobe Shape CC FAQ
    " Vector shapes created using the Adobe Shape CC app are available for use in both desktop and mobile apps. Save the shape in a Creative Cloud library, and it is available for use in Illustrator CC, Photoshop CC on your desktop, and Adobe Illustrator Draw on mobile."

  • Please, help... I need to convert an Illustrator document into .pdf

    Does anybody can help me? I have a document in Adobe Illustrator Artwork 12.0 but don't have the program to open it (and don't know which one I need)
    If I send the document, could you please convert it into .pdf or word. It's a letterhead for the church I work at.
    Thank you very much.

    E-mail the Illustrator document to me at the following address:
    harron {at mark} kurakichi {dot} com
    If you can, put the .ai document in a .zip archive before e-mailing.

  • PDF is changing all my pdf documents into a word document - My boss sent me a pdf email through outlook and when I try to open it changes to a word document

    PDF is changing all my pdf documents into a word document - My boss sent me a pdf email through outlook and when I try to open it changes to a word document Help this is so frustrating

    Hi tinam74565130,
    That does sound frustrating! It sounds as though the filename associations have become confused on your computer. You should be able to reset that easily. Here are some instructions:
    Change which programs Windows uses by default - Windows Help
    How to change the default application for a file type | Macworld
    Please let us know how it goes.
    Best,
    Sara

  • Where is the folder into which place the swf file for Illustrator Extensions

    Hi all,
    I can place swfs into Photoshop & Indesign panels folder and they appear just fine in the extension menu but wherever I place the swf into Illustrator's folders, it just appears nowhere. Can someone tell me where do I have to place them ?
    TIA Loic

    Hi Harbs,
    thx for your answer. As I don't have Extension builder installed yet, I do extensions with Flex and csaw libs, so it is easier for me to debug placing the swf directly into the folders like for Photoshop and Indesign. Of course in the end I would have set a correct extension but for now it was better for me to do this way.
    So what I understand is that there is no way to get that behaviour with Illustrator unless I do process and install a whole extension package. Annoying but well, will have to deal with it.
    Thx Loic

  • I can longer place PSD files into Illustrator. Only jpgs are working. I'm using CS4 and Yosemite. What's up?

    I can longer place PSD files into Illustrator. Only jpgs are working. I'm using CS4 and Yosemite. What's up?
    Creative Suites

    THat's a bug/ compatibility issue in Yosemite.
    Mylenium

  • How do i place a pages template into a pages document?

    I have created a poster from the pages template and i want to resize the poster to use as an advertisement in another pages document i have created.
    how do i do this?
    TIA

    Print it as a .pdf, drag that into the 2nd document and reduce its size as necessary.
    Alternatively you can relayout the poster, which would be normal for an advertisement, omitting some of the irrelevant detail and simplifying it. You can group textboxes, images and shapes then reduce them as a whole. The actual text within the boxes won't shrink, but you can reduce the point size and leading, preferably in named styles, to suit.
    Peter

  • Can I use ExtendScript to store info about an Illustrator document externally and recover it later?

    What I want to do is this:
    1. Iterate through all the layers in a document (recursively) and discover each layer's NAME, VISIBLE, and LOCKED properties.
    2. Create an object that contains those properties.
    3. Push the object onto a second array.
    4. Store that second array somewhere, preferably in a file (text?) in the same directory as the AI document.
    5. Load that file at a later date as an object array.
    6. Use the object array to iterate through the illustrator document to conform the current state of that document to the stored states in the array.
    Ideally I would like to be able to store a number of separate states in the same document and refer to them somehow.
    As you may have guessed by now, this is my attempt to make a LayerComps feature for Illustrator that I could use to turn visibilities on and off and then export the result, moving on from one state to the next until all the states I am interested in would be exported. I would settle for being able to do it one at a time.
    I can already do steps 1-3 (shown in blue).
    var doc = app.activeDocument;
    var docName = doc.name;
    var layerStates = [];
    var layerCount = doc.layers.length;
    var count = 0;
    function addLayers(layerArray) {
            for (var i=0; i<layerArray.length; i++) {
                // create an object representing a layer state
                var o = {};
                o.name = layerArray[i].name;
                o.visible = layerArray[i].visible;
                o.locked = layerArray[i].locked;
                layerStates[count] = o;
                count++;
                // if this layer has layers of its own, iterate through those
                if (layerArray[i].layers.length > 0) {
                        addLayers(layerArray[i].layers);
    addLayers(doc.layers);
    // show that we did something, incomplete though it is
    var s = "";
    for (var i=0; i < layerStates.length; i++) {
            s += layerStates[i].name + ": ";
            s += (layerStates[i].visible ) ? "visible" : "invisible";
            s += ", ";
            s += (layerStates[i].locked ) ? "locked" : "unlocked";
            s += "\n";
    alert(s);
    I don't know if it is possible to export that data as XML or even a text string and save it as a file on the file system for later parsing. Anyone have any thoughts about this? Is it possible?
    Currently I am using a restrictive version of a LayerComps script I created, which iterates through a top layer's sublayers, turning each on and exporting as PDF, then turning it off and moving to the next. This is more convenient than doing it by hand, but it really forces me to compartmentalize all "views" of a document in a way that does not lend it self to efficiency and forces redundant copying of pathItems between layers.
    Thoughts?

    Also good, and thanks again for your help. I wasn't sure if ExtendScript implemented the eval() method, necessary to re-objectify a JSON string, because I can't find it in the documentation, but I do see it used in some examples elsewhere. I've successfully written XML files at this point, and when I get a few minutes I'll work on the reading/modifying/exporting part. In the long run, XML files are easier to read, manipulate and maintain, so I'll probably go that route.
    var doc = app.activeDocument;
    var docName = doc.name;
    var xml = new XML("<root></root>");
    var layerStates = [];
    var layerCount = doc.layers.length;
    var count = 0;
    function addLayers(layerArray, xmlObj) {
        for (var i=0; i<layerArray.length; i++) {
            // create an object representing a layer state
            var lay = layerArray[i];
            var x = new XML("<layer/>");
            x.@name = lay.name;
            x.@visible = lay.visible;
            x.@locked = lay.locked;
            xmlObj.appendChild(x);
            layerStates[count] = x.toXMLString();
            count++;
            // if this layer has layers of its own, iterate through those
            if (lay.layers.length > 0) {
                addLayers(lay.layers, x);
    addLayers(doc.layers, xml);
    var xmlFile = new File();
    xmlFile.open('w');
    xmlFile.write(xml);
    xmlFile.copy ('C:/Program Files (x86)/Adobe/Adobe Illustrator CS4/Presets/en_US/Scripts/data.xml');
    xmlFile.close();
    All in all, the documentation for this stuff leaves a little something to be desired. My original question had more to do with how file read and write text streams was handled. The answer was actually much simpler than I anticipated. All this stuff is, once you get a handle on it, but the docs are so stingy on particulars — does it really help us to know about the XML class merely that it "wraps XML into an object" or that XML.attribute(name) "returns a list containing all attribute elements matching the given name"? I finally worked it out for myself that the XML object may be manipulated using dot syntax (x.name, x.@name), but that was certainly not mentioned anywhere.
    Ah, well. The journey is the reward, right?

  • Pasting from Microsoft Word into Adobe Illustrator...problem

    Hello gang, I'm a professional comic book letterer and I recently decided to upgrade from using TextEdit to using Microsoft Word for all of my script copy pasting that I have to do.
    In TextEdit when I copy a page from a comic script it will then paste into Adobe Illustrator beautifully. Retains line breaks and formatting really well (doesn't remember bolds or italics, but oh well). However, when I paste from the Word version of the same script, all the line breaks disapear, leaving me with a big square block of text, making it hard for me to easily find dialogue to use on the page.
    Does anyone have a solution for this? Is this a known issue with Word? I can't seem to find anything about it on the net.
    I'm using Word 11 for Mac version 14.2.1 I think it is and Adobe Illustrator CS3 for Mac.
    Running Snow Leopard on a MacBook Pro for what that's worth. Verion 10.6.8
    thanks,
    -- J

    When I tried to place a 12 pages Word doc in Illustrator CS5, the same way told by John_Danek, I could see a small + sign on the bottom right corner of the text box. If you double click that text box, you can see page 2 of the doc. Similarly, you can view all the pages of your Word doc in Illie.
    OR
    If save your content in a PDF and then place the PDF in Illustrtaor. This will help you retain formatting as well as will allow you selecting page numbers of your document you want to place.

Maybe you are looking for