5 Replies Latest reply on Nov 18, 2011 3:04 AM by Laubender

    [JS] Exporting InDesign group as eps

    MatthewMariani Level 1

      Although all types of page items have an exportFile method in the object model, it does not seem to be possible to export a group of page items on a given page without exporting the entire

      parent page using the exportFile method. Maybe this is a matter of implementation lagging behind documentation? In any case, I have used workarounds such as the following, but is there is a less clunky way to accomplish this task?

       

      //Initial selection is either a group of page items or a single page item.
      var d = app.documents[0];
      var hUnits = d.viewPreferences.horizontalMeasurementUnits;
      var vUnits = d.viewPreferences.verticalMeasurementUnits;
      aGroup = app.selection[0];
      path = app.documents[0].fullName.absoluteURI;
      path = path.substring( 0, path.lastIndexOf('/') );
      bnds = aGroup.geometricBounds;
      var nd = app.documents.add(false);
      with ( nd.masterSpreads[0].pages[0].marginPreferences ) {
        top = bottom = left = right = 0;
      }
      with ( nd.viewPreferences ) {
        horizontalMeasurementUnits = hUnits;
        verticalMeasurementUnits = vUnits;
      }
      with ( nd.documentPreferences ) {
        pageHeight = bnds[2] - bnds[0];
        pageWidth = bnds[3] - bnds[1];
      }
      var copiedGroup = aGroup.duplicate( nd.layers[0] );
      copiedGroup.move( [0,0] );
      copiedGroup.exportFile( ExportFormat.EPS_TYPE, File( path + '/' + 'TEST.eps' ), false );
      nd.close(SaveOptions.NO);
      
      
        • 1. Re: [JS] Exporting InDesign group as eps
          John Hawkinson Level 5

          This is a known limitation.

          1 person found this helpful
          • 2. Re: [JS] Exporting InDesign group as eps
            Laubender Adobe Community Professional & MVP

            Hi, Matthew!
            I'd play save and would do the following:

             

            1. export whole page to EPS
            2. store visibleBounds, not geometricBounds of the group for further use
            3. add new doc with the visible bounds of the group

            4. place the EPS so that your group elements are in the exact center of that new doc (you can do so by calculating the page bounds against the visible bounds of your group)
            5. export again to EPS

             

            Background: if you duplicate a text frame to a new document it is not unlikely that you end up with new text wraps. Consider also the possibility that your text base line will shift because your paragraph styles are set to "align to baseline grid" and the baseline grid of your new document differs from the source.

             

            Uwe

            1 person found this helpful
            • 3. Re: [JS] Exporting InDesign group as eps
              MatthewMariani Level 1

              Hello Uwe,

               

              Thanks for the advice! I took your suggestion, and I find it worked nicely, after I adjusted pasteboardMargin preferences in the new document, but it does fail when there are multiple eps images already placed on the target page for reasons that are not clear to me. Below are the two different methods I came up with, the first copies the targeted group to a new doc, and the second uses your double eps export method. The problem I describe occurs even when I comment out the lines that remove the temporary eps file and close the temporary InDesign doc after exporting the final eps, which I thought might be causing the problem. Maybe there's not a perfect workaround, but I'd be pleased to be proven wrong in that regard!

               

              Copy group selected for eps export to new document method:

               

              var d, hUnits, vUnits, aGroup, path, bnds, nd, copiedGroup, fileName, docPreset;
              if ( app.documents.count() != 1 || app.documents[0].saved != true || app.documents[0].selection.length != 1 ) { alert("A single, saved document must be open with a single item selected!\r"); exit(); }
              aGroup = app.selection[0];
              d = app.documents[0];
              hUnits = d.viewPreferences.horizontalMeasurementUnits;
              vUnits = d.viewPreferences.verticalMeasurementUnits;
              path = app.documents[0].fullName.absoluteURI;
              path = path.substring( 0, path.lastIndexOf('/') );
              bnds = aGroup.visibleBounds;
              fileName = prompt( "Enter a file name with a '.eps' extension for the eps file to be created from the  current selection:", ".eps" );
              if ( fileName == null  ) exit();
              if ( fileName.toLowerCase().search(/\.eps$/) < 1 ) {
                alert( "Invalid file name provided. Script will terminate!" ); exit();
              }
              docPreset = app.documentPresets.add({top:0, bottom:0, left:0, right:0});
              app.scriptPreferences.enableRedraw = false;
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
              nd = app.documents.add(true, docPreset );
              with ( nd.viewPreferences ) {
                horizontalMeasurementUnits = hUnits;
                verticalMeasurementUnits = vUnits;
              }
              with ( nd.documentPreferences ) {
                pageHeight = bnds[2] - bnds[0];
                pageWidth = bnds[3] - bnds[1];
              }
              copiedGroup = aGroup.duplicate( nd.layers[0] );
              copiedGroup.move( [0,0] );
              copiedGroup.exportFile( ExportFormat.EPS_TYPE, File( path + '/' + fileName ), false );
              nd.close(SaveOptions.NO);
              docPreset.remove();
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
              app.scriptPreferences.enableRedraw = true;
              
              

               

              Double eps export method:

               

              var d, pg, hUnits, vUnits, aGroup, path, bnds, pgbnds, nd, fileName, tempFileName, docPreset;
              if ( app.documents.count() < 1 || app.documents[0].saved != true || app.documents[0].selection.length != 1 ) { alert("A saved document must be open with a single group or a single page item selected!\r"); exit(); }
              aGroup = app.selection[0];
              d = app.documents[0];
              pg = aGroup.parentPage;
              pgbnds = pg.bounds;
              hUnits = d.viewPreferences.horizontalMeasurementUnits;
              vUnits = d.viewPreferences.verticalMeasurementUnits;
              path = app.documents[0].fullName.absoluteURI;
              path = path.substring( 0, path.lastIndexOf('/') );
              bnds = aGroup.visibleBounds;
              fileName = prompt( "Enter a file name with a '.eps' extension for the eps file to be created from the  current selection:", ".eps" );
              if ( fileName == null  ) exit();
              if ( fileName.toLowerCase().search(/\.eps$/) < 1 ) {
                alert( "Invalid file name provided. Script will terminate!" ); exit();
              }
              tempFileName = Math.random().toString() + '.eps';
              app.epsExportPreferences.pageRange = pg.name;
              d.exportFile( ExportFormat.EPS_TYPE, File( path + '/' + tempFileName ), false );
              app.epsExportPreferences.pageRange = PageRange.ALL_PAGES;
              docPreset = app.documentPresets.add({top:0, bottom:0, left:0, right:0});
              app.scriptPreferences.enableRedraw = false;
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
              nd = app.documents.add(true, docPreset );
              nd.pasteboardPreferences.pasteboardMargins = [ (pgbnds[3] - pgbnds[1])*2, (pgbnds[3] - pgbnds[1])*2 ];
              with ( nd.viewPreferences ) {
                horizontalMeasurementUnits = hUnits;
                verticalMeasurementUnits = vUnits;
              }
              with ( nd.documentPreferences ) {
                pageHeight = bnds[2] - bnds[0];
                pageWidth = bnds[3] - bnds[1];
              }
              nd.pages[0].place( File(  path + '/' + tempFileName ), [ pgbnds[1] - bnds[1], pgbnds[0] - bnds[0] ], undefined, false, false );
              nd.exportFile( ExportFormat.EPS_TYPE, File( path + '/' + fileName ), false );
              nd.close(SaveOptions.NO);
              File(  path + '/' + tempFileName ).remove();
              docPreset.remove();
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
              app.scriptPreferences.enableRedraw = true;
              
              
              • 4. Re: [JS] Exporting InDesign group as eps
                John Hawkinson Level 5

                This is a known limitation.

                Rereading this, I realize I may have been unclear or even wrong.

                I was referring to the limitation that you cannot export a set (not a group) of objects using the Scripting DOM, but that you have to group them first (there is no API to export an array of PageItems). I believe this is InDesign bug #2922303.

                 

                The fact that exporting a group of 2 items causes other items on the page to appear in the EPS export is a different problem. So don't fail to file a bug on my account!

                 

                Though I suppose it may not be a bug – I don't see a way to do this in the UI. Selecting objects and exporting exports the page. unlike as with snippets.

                 

                I would think Acrobat would be a better tool to clip eps files (or maybe just clip them by hand with raw postscript?). But hey, if it works...

                • 5. Re: [JS] Exporting InDesign group as eps
                  Laubender Adobe Community Professional & MVP

                  @John: and I thought you mean the "limitation" that if you use exportFile on a group you always get the whole page… ;-)

                   

                  One afterthougt:
                  a severe problem with group.exportFile could be, that underneath or above the group there could be  other page objects positioned you don't want to export. So we have to include a further step in the script to  isolate the group first (move it to a separate layer, do not include all other layers while exporting).


                  Plus:
                  if we want to go the Acrobat pdf-route, we need some Acrobat scripting and a way to transfer visibleBounds-data of the group to Acrobat to change MediaBox, CropBox, TrimBox etc..

                   

                  I think (at least for me) it's less complicated to use InDesign instead and exporting twice.

                   

                  Uwe