7 Replies Latest reply on Sep 25, 2008 10:24 PM by Loic.Aigon

    Script for Exporting 2 Pgs into 1 PDF???

    Level 1
      Hello, I was wondering if anyone can help me. I know there is a script that can export each page of Indesign file as a separate PDF, but is there a script out there to export every two pages of Indesign file.

      Basically what I need to do is create 300 customized documents (based on personal company information) and Export them to a PDF so that I may e-mail one to each company. The document must be two pages, the first page has the personalized (merged) information, but the second page will be exactly the same on all of them.

      Can you tell me how I can do this in Indesign, or if not Indesign, Acrobat? I ran a test with the Data Merge system in Indesign. (I created a .CSV file with 2 columns; Company Name and Company Product and took 5 five companies from the master list to test.)

      After the merge, all the fields populated correctly but I wound up with a 10 page .INDD document. (the odd number pages are the ones with all the "merged" personal info, while all the even number pages exactly the same) What I need now is every 2 pages to be exported as 1 PDF file.

      Is there is an easier way to do this? And if not in Indesign, is there an easy way to extract 2 pages at a time in Acrobat?

      Thank you very much for any help, much appreciated,

      Kevin
        • 1. Re: Script for Exporting 2 Pgs into 1 PDF???
          Loic.Aigon Adobe Community Professional
          Hi try this one.
          Assuming that you merge correctly the datas and that you only need to export the PDFs. Assuming too that your doc is effectively 300pages long or consists in a even number of pages.
          Here is a very basic script, fell free to accomodate to your needs.

          ad = app.activeDocument;
          pg=ad.pages;
          var docpath = ad.filePath;
          for(i=0; i<(pg.length/2);i++)

          {
          ]app.pdfExportPreferences.pageRange = 2*pg[i].index+"-"+(2*pg[i].index+1);
          ]var myPDFExportPreset = app.pdfExportPresets.item("prepress"); //enter the name of your PDF preset
          ]ad.exportFile(ExportFormat.pdfType, File(docpath+"/pg_"+i+"_to_"+(i+1)+".pdf"), false, myPDFExportPreset);

          }
          alert("done");
          • 2. Re: Script for Exporting 2 Pgs into 1 PDF???
            Level 1
            Hi Loic, thank you sooooo much for this, I appreciate you helping me out.

            I just have one little problem...I actually don't know how to manipulate JavaScript or how or where I would use this code. Basically all I do know how to do is take a Script file and install in the Scripts folder so I can use it in Indesign.

            Would you mind helping me out a little further on this?

            Thanks again..
            • 3. Re: Script for Exporting 2 Pgs into 1 PDF???
              Loic.Aigon Adobe Community Professional
              Hi Kevin,<br />Here is another version.<br />copy/paste into a text editor then save as a .jsx and place it in the script folder.<br />The only thing you have to modify is the name of your pdf preset. I thought about a dialog where tou could have switched frome one preset to another easily. But it may much more efficient to just modify the name of the preset. If you want you an also make a copy with another PDF preset then rename it.<br /><br />ad = app.activeDocument;<br />pg=ad.pages;<br />var docpath = ad.filePath;<br />var docname = ad.name;<br />var nb = (Math.round(Number(pg.length/2)))<br />for(i=0; i<nb;i++)<br /><br />{<br />]var pgrgstart = (pg[(2*i)].name);<br /><br />]if(pg[(2*i+1)]==-1)<br /><br />]{<br /><br />]]var pgrgend = pgrgstart;<br /><br />]}<br /><br />]else<br /><br />]{<br /><br />]]var pgrgend = pg[(2*i+1)].name;<br /><br />]}<br /><br />]app.pdfExportPreferences.pageRange = pgrgstart+"-"+pgrgend; <br /><br />]var myPDFExportPreset = app.pdfExportPresets.item("your PDF preset"); <br /><br />b //enter the name of your PDF preset instead of your PDF preset<br /><br />]ad.exportFile(ExportFormat.pdfType, File(docpath+"/"+docname.split(".indd")[0]+"_"+"pg_"+i+"_to_"+(i+1)+".pdf"), false, myPDFExportPreset); <br /><br />}<br /><br />alert("done");
              • 4. Re: Script for Exporting 2 Pgs into 1 PDF???
                Level 1
                thank you very much, I really appreciate it.
                • 5. Re: Script for Exporting 2 Pgs into 1 PDF???
                  Loic.Aigon Adobe Community Professional
                  Hi I realized it could be finer. When you have a odd number of pages, the last pdf will be one page only. That's ok but rigth now, its pdf name will be   ...pg_198_to_198<br />Not really pretty<br />ad = app.activeDocument;<br />pg=ad.pages;<br />var docpath = ad.filePath;<br />var docname = ad.name;<br />var nb = (Math.round(Number(pg.length/2)))<br />for(i=0; i<nb;i++)<br /><br />{<br /><br />]var pgrgstart = (pg[(2*i)].name); <br /><br />]if(pg[(2*i+1)]==-1) <br /><br />]{ <br /><br />]]var pgrgend = pgrgstart;<br /><br />]]var P = ""; <br /><br />]} <br /><br />]else <br /><br />]{ <br /><br />]]var pgrgend = pg[(2*i+1)].name; <br /><br />]]var P = "_to_"+(i+1);<br /><br />]} <br /><br />]app.pdfExportPreferences.pageRange = pgrgstart+"-"+pgrgend; <br /><br />]var myPDFExportPreset = app.pdfExportPresets.item("your PDF preset"); <br /><br />]//enter the name of your PDF preset instead of your PDF preset<br /><br />]ad.exportFile(ExportFormat.pdfType, File(docpath+"/"+docname.split(".indd")[0]+"_"+"pg_"+i+P+".pdf"), false, myPDFExportPreset); <br /><br />}<br />it should be cleaner this way
                  • 6. Re: Script for Exporting 2 Pgs into 1 PDF???
                    Level 1
                    Hey thanks a lot....I was curious, I really want to learn Javascript as it relates to Indesign. How would you say I go about starting to learn. Keeping in mind that i have absolutely no experience with Javascript. Sometimes I try and read forums, search for information and I get a lot of information that I dont understand....But do you think you could explain, in general terms, how it works and what all you can do with it. Is dreamweaver a good program to write scripts for indesign?

                    hehe, on the one hand I do know HTML ok(very basic HTML). I create pretty good looking emails using basic HTML...And a long time ago,
                    I have taken a few VB programming classes. So the idea of programming, tags, styles...etc.... isn't lost on me.

                    Thanks for any advice....

                    Kevin
                    • 7. Re: Script for Exporting 2 Pgs into 1 PDF???
                      Loic.Aigon Adobe Community Professional
                      Your 're welcome.
                      For me, I started learning with the Peter's Karhel guide :
                      http://oreilly.com/catalog/9780596528171/ index.html
                      It is worth paying for it because it's very helpful.
                      Then I used the free adobe guide & reference manual because once you "understood" the logic and the fact that you couldn't use any method every object, then, the first bricks aren't such difficult to gather.
                      The main difficulty and I thin I am so far from that is to master the script rationality.
                      At first you write heavy stuffs, but then learning & learning you improve your way of thinking scripts.
                      You can use a simple text editor to write scripts but I don't think this is a good way for a beginner.
                      Using ESTK is really helpful because in CS3 you hav all the object model libraries in the help menu. And as long as you write a line, theESTK foresse what you want and propose you the ed of your line or offer methods linked to your word.
                      Moreover, you can of course debug line by line, seeing the values...
                      Definitely the ESTK, not dreamweaver.
                      Once you are an expert, maybe the notepad will be enough maybe.

                      To summarize, scripting as far as I understood it is to adress properly objects and tell them to do thing that they are intended to.

                      Once again have a look at the Peter's Karhel guide, that's very a great starting point.