5 Replies Latest reply on Jul 7, 2011 2:07 AM by getZinger

    finding then combining content from several indesign documents in one document

    simondawdry

      Hi everyone,

       

      I wonder if someone can help...

       

      I'm trying to write scripts for indesign server which I want to:

      a) search for,

      b) pick out, then

      c) put together content from one or many indesign documents into a template on the server starting at a pre-defined point in the template. 

       

      After that we produce a pdf of the document to pass on / do whatever. I've got so far with the scripting documentation but I'm stuck!  This is what I've done so far:

       

      1/ create a document template with a script
      2/ add text elements to the document template (header and footnote, title,       body text i.e. intro and data, and the contact details)
      3/ add text / content from another indesign file into this       document (so far only done it with a .txt file) ...

      ... I'm stuck on the indesign documents at the moment.  I have       looked at various options, the most appropriate way I can see in       the manuals to get content from one document to another is by       duplicating.  My understanding is to do this you have to target the text in the source       document, duplicate it and then add it into a text frame on the       target document.  It's the targettting of the text and surrounding       elements in the source document I'm battling with. 

       

      any ideas on how I go about this effectively? 

       

      Any help and advice appreciated!

        • 1. Re: finding then combining content from several indesign documents in one document
          simondawdry Level 1

          ok, I made a bit of progress with this, but there's a couple of things going on which I could do with some help on as my scripting isn't too hot, I've adapted it from sample scripts...

           

          1/ getting this to run on indesign server

          2/ altering the scrip to accept more than one pdf file

           

          here's the scripty bit...

           

          try{

          for(myCounter = app.documents.length; myCounter > 0; myCounter--){

          app.documents.item(myCounter-1).close (SaveOptions.no);

          }

            myDocument = app.open(File("Z:/template.indd"));

          insertPdf();

          function insertPdf(){

              var myPage = myDocument.pages.item(2);

              var myPDFFile = File("Z:/insert.pdf");

              myPlacePDF(myDocument, myPage, myPDFFile);

              myDocument.exportFile(ExportFormat.pdfType, new File("Z:/combined.pdf"), false);

              myDocument.close(SaveOptions.no);

          }

           

          }catch(e) { myDocument.close(SaveOptions.no); }

           

          function myPlacePDF(myDocument, myPage, myPDFFile){

          var myPDFPage;

          app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;

          var myCounter = 1;

          var myBreak = false;

          while(myBreak == false){

          if(myCounter > 1){

          myPage = myDocument.pages.add(LocationOptions.after, myPage);

          }

          app.pdfPlacePreferences.pageNumber = myCounter;

          myPDFPage = myPage.place(File(myPDFFile), [0,0])[0];

          if(myCounter == 1){

          var myFirstPage = myPDFPage.pdfAttributes.pageNumber;

          }

          else{

          if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){

          myPage.remove();

          myBreak = true;

          }

          }

          myCounter = myCounter + 1;

          }

          }

           

           

          Thanks for reading, if you've any ideas I'd love to hear them! :-)

          • 2. Re: finding then combining content from several indesign documents in one document
            getZinger

            Running it on InDesign Server can be done from the ESTK, but that probably isn't wat you are looking for.Let someone else help you with that

             

            For accepting more than 1 pdf, you can store all pdf(filename)'s in an array, and loop through that array.

            So myPDFFiles = ["myFirstName","mySecondName","myThirdName"];

            Now you can loop through them,

             

            for(myIndex=0;myIndex<myPDFFiles.length;myIndex++){

            myPDF = File(myPDFFiles[myIndex])

            //and now do with the file as you like;

            }

            //keep the common things like exporting outside the loop ofcourse.

             

            Good luck

            1 person found this helpful
            • 3. Re: finding then combining content from several indesign documents in one document
              simondawdry Level 1

              thanks getZinger, I'll give this a shot :-)

              • 4. Re: finding then combining content from several indesign documents in one document
                simondawdry Level 1

                The story so far...

                 

                I've added the code kindly provided by getZinger (thanks again!) and am now stuck on the next stage, .  I've commented the code where I'm having problems, and essentially have two key issues to resolve:

                 

                1/ how I get the documents to be placed one after the other, avoiding the overlay I get on the first insertion page.

                   (I am using a fixed value as an insert point as the template I'm using will always have inserts starting on page 3).

                 

                2/ how I access the pdf's I want to insert from a location other than C:\Users\Whoever\Documents\

                 

                /*
                try{
                for(myCounter = app.documents.length; myCounter > 0; myCounter--){
                app.documents.item(myCounter-1).close (SaveOptions.no);
                }
                */
                  myDocument = app.open(File("C:/.../template.indd"));
                  myPDFFiles = ["pdf1.pdf","pdf2.pdf","pdf3.pdf"];
                
                insertPdf();
                function insertPdf(){
                //I've gone for a static number here as the datapage in the skeleton doc  is page 3.
                //This seems to result in some of the pages being placed on top of each  other :-(
                    var myPage = myDocument.pages.item(2);
                    /*var myPageNames = new Array;
                    //Get the names of the pages in the document
                    for(var myCounter = 0; myCounter < myDocument.pages.length;myCounter++){
                        myPageNames.push(myDocument.pages.item(myCounter).name);
                    }*/
                    var myPDFSet = File("C:/Users/Simon/Desktop/Mexico.pdf");
                    for(myIndex=0;myIndex<myPDFFiles.length;myIndex++){
                    myPDFSet = File(myPDFFiles[myIndex])
                    myPlacePDF(myDocument, myPage, myPDFSet);
                    }
                    myDocument.exportFile(ExportFormat.pdfType, new File("C:/.../test_insert.pdf"), false);
                    myDocument.close(SaveOptions.no);
                }
                /*
                }catch(e) { myDocument.close(SaveOptions.no); }
                */
                function myPlacePDF(myDocument, myPage, myPDFSet){
                var myPDFPage;
                app.pdfPlacePreferences.pdfCrop = PDFCrop.cropMedia;
                var myCounter = 1;
                var myBreak = false;
                while(myBreak == false){
                if(myCounter > 1){
                myPage = myDocument.pages.add(LocationOptions.after, myPage);
                }
                app.pdfPlacePreferences.pageNumber = myCounter;
                //the files seem to be automatically placed from C:\Users\Whoever\Documents 
                //I need to change this to accept a different file path somehow but I  don't know how
                //this is why the myPDFFiles array only has filenames at the moment
                myPDFPage = myPage.place(File(myPDFSet), [0,0])[0];
                if(myCounter == 1){
                var myFirstPage = myPDFPage.pdfAttributes.pageNumber;
                }
                else{
                if(myPDFPage.pdfAttributes.pageNumber == myFirstPage){
                myPage.remove();
                myBreak = true;
                }
                }
                myCounter = myCounter + 1;
                }
                }
                

                 

                once again, thanks for taking the time to read this, any help greatly appreciated :-)

                • 5. Re: finding then combining content from several indesign documents in one document
                  getZinger Level 1

                  1/ how I get the documents to be placed one after the other, avoiding the overlay I get on the first insertion page.

                     (I am using a fixed value as an insert point as the template I'm using will always have inserts starting on page 3).

                   

                  catch the placedPDF.geometricBounds[2], which is the bottom coordinate of your pdf.

                  catch the newpdf height (newpdf.geometricBounds[2]-newpdf.geometricBounds[0];

                  if pageheight - placedPDF.geometricBounds[2](+needed spacing)  isn't smaller than your new pdf height, place your new pdf at

                  y=placedPDFGeoB[2]+needed spacing;
                  else

                  pace it at next page.

                   

                  2/ how I access the pdf's I want to insert from a location other than C:\Users\Whoever\Documents\

                  and from what location do you want them to come?