5 Replies Latest reply on Dec 23, 2014 3:26 AM by Stamm

    SVG in Indesign CC?

    Stamm Level 1

      Hey guys,

       

      this topic has been around many times, but you always only read things like "use scand" and "the support is not really good" and that's it. I am using Indesign CC so Scand is not an option.

       

      I need to be able to export custom shapes (polygons, custom paths f.e.) as svg. I can get this working, if the computer has installed Adobe Illustrator. Then you could use copy paste to copy a custom shape to Illustrator and then export the svg code from there, save it in a variable and put it in your indesign xml.

       

      But when scand can export svgs, shouldn't it be also possible to do it by hand, javascript only?

       

      As it is for now, I only know the geometricBounds property, but can you get all information of the objects? Every path, the rotation of points in this path, etc? I would really like to find a indesign solution ONLY.

       

      Does anyone have some ideas on this? Time doesn't matter, as I have no deadline for this. I just need to get it to work somehow.

        • 1. Re: SVG in Indesign CC?
          Harbs. Level 6

          There's two approaches you can take:

          1) walk through the InDesign properties of an object, and construct the SVG XML from that. The most important property for constructing basic SVG is the fullPath.

          2) Export an object as a snippet file and do a transform on the snippet XML.

           

          Both approaches should be viable using ExtendScript. The difficulty involved will depend on how complex your objects are.

           

          If you do work on this, I'd be interested in seeing your progress. If I have extra time I might even be prone to help...

           

          Harbs

          • 2. Re: SVG in Indesign CC?
            Harbs. Level 6

            FWIW, it looks like Scand uses (used?) Apache Batik for the SVG manipulation. Using outside libraries from ExtendScript is possible, but tricky. For basic SVG, the ExtensScript translation approach seems like a reasonable approach.

            • 3. Re: SVG in Indesign CC?
              Stamm Level 1

              Hey, after posting this thread I also found out about the Path property. I guess this is the way to go. I will try something out and come back here as soon as I got the first code. Thank you!

              • 4. Re: SVG in Indesign CC?
                Laubender Adobe Community Professional & MVP

                @Stamm – if you have a version of InDesign CS3 at hand, you could export SVG from there.

                In CS4 this feature was removed.

                 

                Uwe

                • 5. Re: SVG in Indesign CC?
                  Stamm Level 1

                  Hey Harbs,

                   

                  I've come quite far I think.

                   

                  function getPath(object){ 

                          path = object.paths[0].entirePath;

                          bounds = object.geometricBounds;

                          points = [];

                          for(i = 0; i< path.length+1; i++){

                              if(i !== path.length){

                                  if(path[i].length === 2){

                                      if(i !== 0){

                                          if(path[i-1].length === 3 && path[i-1][1] !== path[i-1][2]){

                                              points[i] = 'C ' + [ path[i-1][2][0] - bounds[1] , path[i-1][2][1] - bounds[0] ] + ' ' + [ path[i][0] - bounds[1] , path[i][1] - bounds[0] ] + ' ' + [ path[i][0] - bounds[1] , path[i][1] - bounds[0] ];

                                          }

                                          else{

                                              points[i] = 'L ' + [ path[i][0] - bounds[1] , path[i][1] - bounds[0]];

                                          }

                                      }

                                      else if( i === 0){

                                          points[i] = 'M ' + [path[i][0] - bounds[1] , path[i][1] - bounds[0]];

                                      }

                                  }

                                  else{

                                      if(i !== path.length-1){

                                          if(i !== 0){

                                              if(path[i-1].length === 3 && path[i-1][1] !== path[i-1][2] && path[i][0] !== path[i][1]){

                                                  points[i] = 'C ' + [ path[i-1][2][0] - bounds[1] , path[i-1][2][1] - bounds[0] ] + ' ' + [ path[i][0][0] - bounds[1] , path[i][0][1] - bounds[0] ] + ' ' + [ path[i][1][0] - bounds[1] , path[i][1][1] - bounds[0]];

                                              }

                                              else if(path[i-1].length !== 3 && path[i-1][2] === path[i-1][1] && path[i][0] !== path[i][1]){

                                                  points[i] = 'C ' + [ path[i-1][2][0] - bounds[1] , path[i-1][2][1] - bounds[0] ] + ' ' + [ path[i][0][0] - bounds[1] , path[i][0][1] - bounds[0] ] + ' ' + [ path[i][1][0] - bounds[1] , path[i][1][1] - bounds[0]];

                                              }

                                          }

                                          else if(i === 0){

                                              points[i] = 'M ' + [ path[i][1][0] - bounds[1] , path[i][1][1] - bounds[0] ];

                                          }

                                      }

                                  }

                              }

                              if(i === path.length){

                                  if(path[0].length === 2){

                                      if(path[i-1].length === 3 && path[i-1][1] !== path[i-1][2]){

                                          points[0] = 'C ' + [ path[i-1][2][0] - bounds[1] , path[i-1][2][1] - bounds[0] ] + ' ' + [ path[0][0] - bounds[1] , path[0][1] - bounds[0] ] + ' ' + [ path[i][0] - bounds[1] , path[i][1] - bounds[0] ];

                                      }

                                    

                                      else{

                                          points[i-1] = 'Z ';

                                      }

                                  }

                                   else{

                                      if(path[i-1].length === 3 && path[i-1][1] !== path[i-1][2] && path[0][0] !== path[0][1]){

                                          points[i-1] = 'C ' + [ path[i-1][2][0] - bounds[1] , path[i-1][2][1] - bounds[0] ] + ' ' + [ path[0][0][0] - bounds[1] , path[0][0][1] - bounds[0] ] + ' ' + [ path[0][1][0] - bounds[1] , path[0][1][1] - bounds[0]];

                                      }

                                      else if(path[i-1].length !== 3 && path[0][0] !== path[0][1]){

                                          points[i] = 'C ' + [ path[i-1][0] - bounds[1] , path[i-1][1] - bounds[0] ] + ' ' + [ path[0][0][0] - bounds[1] , path[0][0][1] - bounds[0] ] + ' ' + [ path[0][1][0] - bounds[1] , path[0][1][1] - bounds[0]];

                                      }

                                  }

                              }

                          }

                          return points;

                      }

                   

                  I don't know how clean this is, but with this you are getting a complete path for a polygon.

                   

                  Note: This is yet without strokes, strokeColor and fillColor. It only describes the path for the SVG. Use "alert(getPath(app.activeDocument.selection[0]))" to see what it does.