2 Replies Latest reply on Feb 16, 2017 5:07 AM by jfonts

    Programmatic SVG Export

    erickk56243057 Level 1

      I'm creating an HTML Panel Extension and want to query the Illustrator Canvas path data.  The end goal is to automatically create an SVG of the illustrator file and port this onto the web.  The Javascript API doesn't have an option to save an SVG file, so I'd like to find a way to access the algorithm used for saving an SVG file.

       

      The user should not have to save out an svg file. It would be preferable to send the SVG data from .JSX to HTML/JS. If anyone can point me in the right direction or offer sample files, it'd be very much appreciated!

        • 1. Re: Programmatic SVG Export
          Toto RoToTO Level 3

          Hi,

           

          you could export art to svg using extendscript.

          Here is a sample (.jsx):

          saveAsSVG: function (filePath) {

              try {

                var svgFile = new File(filePath);

                var exportOptions = new ExportOptionsSVG();

                exportOptions.embedRasterImages = ....;

                exportOptions.embedAllFonts = ...;

                exportOptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;

                exportOptions.fontType = SVGFontType.SVGFONT;

                app.activeDocument.exportFile(svgFile, ExportType.SVG, exportOptions);

              } catch (ex) {

               //do whatever you want!

              }

            }

          you could even save selection or asset as svg.

           

          Thomas.

          • 2. Re: Programmatic SVG Export
            jfonts

            Hi,

             

            You mentioned that it can be used to save a selection, but how?

             

            This example is exporting the whole document and I can't find any option for the selection...