7 Replies Latest reply on Nov 8, 2015 2:34 PM by adamg86737138

    Export multiple groups as PDF

    adamg86737138 Level 1

      I've posted a similar question in the past and it was sorted (ended up exporting groups but as JPG). However I would like to export them as PDF now that I know it is possible and have a rough idea of how to achieve this thanks to some members of this forum.

       

      Though I only got a far as the below code. It will resize the page but it looks like to the wrong size - and the group ends up in the pasteboard somewhere.

       

      Would greatly appreciate if someone could point out where I've gone wrong!

       

      var doc=app.activeDocument;  
      var links=doc.links.everyItem().getElements();  
      var fd=new Folder(doc.fullName.parent+'/PDF');  
      if(!fd.exists){
        fd.create();
      }
      var f;  
      for (var i=0;i<links.length; i++){
        if ((links[i].status==LinkStatus.NORMAL||links[i].status==LinkStatus.LINK_EMBEDDED)&&  
        links[i].parent instanceof EPS &&
        links[i].parent.parent.parent instanceof Group){
      
      
          //create new document
          app.documents.add();
      
      
          //duplicate group to new document
          links[i].parent.parent.parent.duplicate(document.pages.item(0));
      
      
          //set bounds of page to bounds of group
          var pg = app.activeDocument.pages.item(0);
          var gBounds = links[i].parent.parent.parent.geometricBounds;
          pg.reframe(CoordinateSpaces.INNER_COORDINATES, [[gBounds[1], gBounds[0]], [gBounds[3], gBounds[2]]]);
      
      
          //export as PDF
          f=File(fd.fullName+'/'+links[i].name.replace(/.[^.]+$/,'')+'.pdf');  
          app.activeDocument.exportFile(ExportFormat.pdfType, f)
      
      
          //exit without saving
          app.activeDocument.close(SaveOptions.NO);
      
      
        }
      }
      

       

      Adam

        • 1. Re: Export multiple groups as PDF
          Peter Kahrel Adobe Community Professional & MVP

          After resizing the page, you need to move the duplicated group to the top left point of the page:

           

          app.documents[0].groups[0].move([0,0]);

           

          Peter

          • 2. Re: Export multiple groups as PDF
            adamg86737138 Level 1

            Thank you, Peter. That solves that issue. However the page is not resizing to the correct size. Seems to be about 4 to 5 times smaller than it needs to be. Any ideas why this would be?

             

            Adam

            • 3. Re: Export multiple groups as PDF
              Peter Kahrel Adobe Community Professional & MVP

              Adam,

               

              It seems more straightforward to create the new document at the correct size so that no resizing is needed. Something like this:

               

              group = links[i].parent.parent.parent;
              gb = group.geometricBounds;
              app.documents.add ({documentPreferences: {pageWidth: gb[3]-gb[1], pageHeight:gb[2]-gb[0]}});
              duped = group.duplicate(app.documents[0].pages.item(0));
              duped.move([0,0]);
              

               

              P.

              • 4. Re: Export multiple groups as PDF
                Jump_Over Level 5

                Hi Adam,

                 

                Watch 2 of activeDoc properties:

                measurmentsUnit and zeroPoint

                 

                reframe method expects POINTS as a unit

                and doc.zeroPoint supposes to be set as [0,0]

                 

                Jarek

                • 5. Re: Export multiple groups as PDF
                  Laubender Adobe Community Professional & MVP

                  Hi Adam,

                  what version of InDesign are you using?

                  I'm just curious…

                   

                  Uwe

                  • 6. Re: Export multiple groups as PDF
                    adamg86737138 Level 1

                    Yes, it would seem more straightforward to do it that way had I known it was possible!


                    Thanks, Peter. I'll definitely keep this in mind. Works perfectly now!

                     

                    I've pasted the full code below just incase anyone else has similar trouble.

                     

                    var doc=app.activeDocument;  
                    var links=doc.links.everyItem().getElements();  
                    var fd=new Folder(doc.fullName.parent+'/PDF');  
                    if(!fd.exists){
                      fd.create();
                    }
                    var f;  
                    for (var i=0;i<links.length; i++){
                      if ((links[i].status==LinkStatus.NORMAL||links[i].status==LinkStatus.LINK_EMBEDDED)&&  
                      links[i].parent instanceof EPS &&
                      links[i].parent.parent.parent instanceof Group){
                    
                    
                        group = links[i].parent.parent.parent;  
                        gb = group.geometricBounds;  
                        app.documents.add ({documentPreferences: {pageWidth: gb[3]-gb[1], pageHeight:gb[2]-gb[0]}});  
                        duped = group.duplicate(app.documents[0].pages.item(0));  
                        duped.move([0,0]);
                    
                    
                        //export as PDF
                        f=File(fd.fullName+'/'+links[i].name.replace(/.[^.]+$/,'')+'.pdf');  
                        app.activeDocument.exportFile(ExportFormat.pdfType, f)
                    
                    
                        //exit without saving
                        app.activeDocument.close(SaveOptions.NO);
                    
                    
                      }
                    }
                    
                    • 7. Re: Export multiple groups as PDF
                      adamg86737138 Level 1

                      Hi Laubender,

                      I'm using Indesign CC 9.2.2

                       

                      Adam