7 Replies Latest reply on Apr 25, 2011 2:38 AM by beh_gras_beh

    Maybe a difficult question?

    beh_gras_beh Level 1

      Dear people,

       

      This script:

       

      var myDoc = app.documents[0];

      app.scriptPreferences.version = "6.0"

       

      if(app.documents.length != 0){  

      var myFolder = Folder.selectDialog ("Choose a Folder");  

      if(myFolder != null){  

      myExportPages(myFolder);  

      }  

      }  

      else{  

      alert("Please open a document and try again.");  

      }  

      function myExportPages(myFolder){  

      var myDocument = app.activeDocument;  

      var myDocumentName = myDocument.name;  

      var myPDFPresets = app.pdfExportPresets;

      var myPDFPresetNames = new Array;

      for (i = 0; i < myPDFPresets.length; i++)

      myPDFPresetNames.push(myPDFPresets[i].name); 

       

      var myDialog = app.dialogs.add();  

      with(myDialog.dialogColumns.add()){ 

       

      with(dialogRows.add()){ 

      with(dialogColumns.add()){ 

      staticTexts.add({staticLabel:"PDF preset: ", minWidth:130}); 

      with(dialogColumns.add()){ 

      var myPDFPresetsDropdown = dropdowns.add({stringList:myPDFPresetNames,  selectedIndex:0}); 

      }

      var myResult = myDialog.show({name:"ExportPages"});  

      if(myResult == true){  

      var myPDFPresetName = myPDFPresetNames[myPDFPresetsDropdown.selectedIndex];

      //Remove the dialog box from memory.  

      myDialog.destroy();  

       

      doc = app.activeDocument;

      doc.sections.everyItem().includeSectionPrefix = false;

      p = app.activeDocument.pages.everyItem().getElements();

      for (i = 0; i < p.length; i++)

       

       

      {  

       

       

      var myRegExp = new RegExp(":","gi");  

      f = File (myFolder + "/" + p[i].textFrames.item ('label').contents + ".pdf");

      app.pdfExportPreferences.pageRange =  p[i].name;  

      myDocument.exportFile(ExportFormat.pdfType,   f, false, myPDFPresets.item(myPDFPresetName));  

      }  

      }  

      }

      can export each page to a PDF in a Indesign document with a specific name you can choose in a textframe.

      But now i want, with a dialogbox, to choose wich page number the script has to export.

      So:

      1. Choose page

      2. Export page

      3. Name the PDF to the text that''s inside the textframe

       

      I was working with app.pdfExportPreferences.pageRange = "number page";

      I thought i had to look in that corner but i think i am searching the wrong direction.

       

      Already thanks to all who wants to help me!

       

       

       

      Greetings from Holland

        • 1. Re: Maybe a difficult question?
          John Hawkinson Level 5
          I was working with app.pdfExportPreferences.pageRange = "number page";

          I thought i had to look in that corner but i think i am searching the wrong direction.

          I'm not sure what your question is. The pageRange property is where you set the number of the page to be exported. But you are doing that and it works fine.

           

          Now you want to add another dialog that prompts for a page number and then sets that property to what the user specifies. How are you stuck?

          • 2. Re: Maybe a difficult question?
            beh_gras_beh Level 1

            Dear John, and other people who reading this,

             

            It's even difficult for me to explain!

            But i'm trying to write a example here:

             

            1. Suppose you have a Indesign document with 4 pages.

            2. Every page has a textframe on it. I labeled that text frame (in the scriptlabel palet) with the text "label".

            3. In that textframe I put on page 1 the tekst "this is page 1" on page 2 "this is page 2, so on and so an.

            4. When I run the script, a diologbox have to ask me wich page I want to export.

            5. I choose page 1 and page 4.

            6. Result: 2 PDF files withe the name "this is page 1.pdf" and "this is page 4.pdf".

             

             

            I was thinking how can i do that with app.pdfExportPreferences.pageRange?

            And i think i'm searching the wrong direction.

             

            I hope i did a better job to explain it to you, my english is worser than worst.

             

            Already thanks for helping me out here!

            • 3. Re: Maybe a difficult question?
              John Hawkinson Level 5

              Your explanation is still very confusing.

               

              When you post javascript, please select >> then Syntax Highlighting > Java so that it formats nicsely.

               

              The code you included above does not appear to include the page selection logic you discussed (#4).

               

              Your existing code loops over all pages and properly sets pageRange when it wants to export a specific page. That's exactly what you need to do in your case, except you don't want to loop over all pages, you only want to loop over the selected pages.

               

              So please post the code that includes that and we can probably tell you the problem.

              • 4. Re: Maybe a difficult question?
                beh_gras_beh Level 1

                Dear John,

                 

                I know it's still confusing and unclear, I can explain it better in my native language but I still going to try so you can understand.

                Your'e totally right that the script loops trough all pages.

                The script you're looking at is indeed a script that works and there is nothing wrong with it.

                 

                The only thing is when I want to ad the code, so that I can choose the page I want to export in stead of the whole indesign document, I realy don't know where to look.

                You'r also right about the script go's trough the whole Indesign document and every page is being exported to separated PDF files.

                That's ok but sometimes when I have 300 pages.

                When I only want page 56 and page 88 I have to run the script and than manualy pic PDF 56 an 88 from the 300 PDF's in the Finder on the Mac (Explorer in Windows).

                I'm very happy with the script as it is but maybe I can work a little bit efficient when I have the option to choose the page rather than I export all pages.

                 

                Don't worry if it's still nut understandable!

                Im still learning and nobody is to old to learn, so maybe i'm coming in a later stadium to a solution!

                 

                 

                Still always thanks for helping me out here!

                • 5. Re: Maybe a difficult question?
                  John Hawkinson Level 5

                  Beh: I think you should concentrate on asking small and answerable questions. Don't ask "How do I get to the moon?" Ask, "where can I buy solid rocket booster fuel?"

                   

                  There are far too many questions that you might be asking, and it is just not clear.

                   

                  I would much prefer you try to do it yourself and then show us how you are stuck. Don't ask us to solve the whole problem for you.

                   

                  Are you asking how to open a dialog box and get the result from a user? OK, use:

                   

                  var pagelist=prompt("Which pages?\nformat: 1,2,3,4");
                  

                   

                  And then 'p' will contain what the user types.

                   

                  Then you need to operate only on those pages. Well, OK. Perhaps you need help with the string processing?

                   

                  var pages = pagelist.split(",");
                  

                   

                  Then pages is an array whose contents are the strings "1", "2", "3", and "4".

                   

                  Then you have lots of choices for how to use that to filter your pages.

                   

                  I would probably convert pages into an Object, because that's much easier to search in Javascript -- you can just use the in operator, like: ('3' in pagesObject) which will return true or false. So:

                   

                  var pagesObject = {};
                  for (i=0; i<pagelist.length; i++) {
                    pagesObject[pagelist[i]] = 1;
                  }
                  

                   

                  Anyhow, then later on you could add a filter to your page looping loop:

                   

                  p = app.activeDocument.pages.everyItem().getElements();
                  for (i = 0; i < p.length; i++) {
                    if (!(p[i].name in pagesObject)) P
                      continue;
                    }
                    var myRegExp = new RegExp(":","gi");
                    ...
                  }
                  

                   

                  etc. But there are hundreds of other ways to do all of these things. Please take the time to ask your questions in way that makes it possible to answer them succinctly.

                   

                  Thanks!

                  1 person found this helpful
                  • 6. Re: Maybe a difficult question?
                    John Hawkinson Level 5

                    Oh yes, while I am here:

                     

                    Please do not use a subject line like "Maybe a difficult question?".

                     

                    It is useless to readers of the forum. Your question is not about solving difficult questions.

                     

                    Your question is about "How to prompt the user?" Or "How to filter a for loop?" Or maybe "Seven basic questions about a script to export selected pages to PDF files." Or worst case, "Please write my script for me. I am reluctant to read the documentation" (I really hope that's not it!).

                     

                    The purpose of the Subject line is to let readers of the forum decide whether they should read a question, and to let people searching in the future find a useful answer that has already been given. Take some time to make it useful to others, please.

                    1 person found this helpful
                    • 7. Re: Maybe a difficult question?
                      beh_gras_beh Level 1

                      John,

                       

                      Thanks for pointing me to the right direction.

                      I'm still learning and I really don't want you to write a script for me, thats not learning!

                       

                      In the future I will post my question more precise.

                      Still thanks for pointing me out to the right direction!

                       

                      I will definitely post my progress on the forum so that other users can use the script.