4 Replies Latest reply on Sep 21, 2015 7:28 AM by evan71922978

    Pick up the texte write in a specify style

    evan71922978

      Hi !

       

      I would like to pick up a texte wrtie in a specify style (like the font, the size...) and put this texte in my ExportPDF script for apply the texte to the name of the exported document.

       

      Like : On my document page, I have a texte write like this : HELLO  ; This saved style is called "page_name". When I export this page to PDF, I want about this HELLO became the name of the PDF. So at the end, in my computeur I want to have a PDF document named HELLO.

       

      That's my ExportPDF script :

      main();  
        
      function main(){  
          mySnippet();  
      }  
         
      function mySnippet(){  
          
           var myPageName, myFilePath, myFile;  
           var myDocument = app.activeDocument;  
           var myBaseName = myDocument.name.replace(/\.indd/, "");  
           var myPDFExportPreset = app.pdfExportPresets.item("[Qualité supérieure]"); 
           for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){  
                myPageName = myDocument.pages.item(myCounter).name;  
                app.pdfExportPreferences.pageRange = myPageName;  
                 
                var myRegExp = /:/gi;  
                myPageName = myPageName.replace(myRegExp, "_");  
                myFilePath = Folder.desktop + "/" + myBaseName + "_" + myPageName + ".pdf";  
                myFile = new File(myFilePath);  
                myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);  
           }  
      }  
      
        • 1. Re: Pick up the texte write in a specify style
          Ronald63 Level 4

          This code suppose :

          - InDesign document with "page_name" paragraph style

          - single occurance of text with  "page_name" ParagraphStyle


          var myDocument = app.activeDocument;
          
          main();  
            
          function main(){
              var myPDFname = extractPAFname()
              exportPDF(myPDFname);  
          }  
                
          function exportPDF(pdfname){  
               //<fragment>  
               var myPageName, myFilePath, myFile;  
               //var myBaseName = myDocument.name.replace(/\.indd/, "");  
               var myPDFExportPreset = app.pdfExportPresets.item("[Qualité supérieure]");  
               for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){  
                    myPageName = myDocument.pages.item(myCounter).name;  
                    app.pdfExportPreferences.pageRange = myPageName;  
                    //The name of the exported files will be the base name + the   
                    //page name + ".pdf". If the page name contains a colon (as it will   
                    //if the document contains sections), then remove the colon.  
                    var myRegExp = /:/gi;  
                    myPageName = myPageName.replace(myRegExp, "_");  
                    myFilePath = Folder.desktop + "/" + pdfname + "_" + myPageName + ".pdf";  
                    myFile = new File(myFilePath);  
                    myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);  
               }  
          }  
          
          function extractPAFname(){  
              var myStyle = myDocument.paragraphStyles.itemByName('page_name');
              if (myStyle.isValid){
                  app.findGrepPreferences = app.changeGrepPreferences = null; 
                  app.findGrepPreferences.appliedParagraphStyle = myStyle;
                  var mySearch = myDocument.findGrep();
                  if (mySearch.length >0){
                      // take the firts item
                      return mySearch[0].contents
                  }else{
                      alert('error message - no text');
                      exit();
                  }
              }else{
                      alert('error message - no style');
                      exit();
                  }
          }
          
          • 2. Re: Pick up the texte write in a specify style
            evan71922978 Level 1

            Error, Impossible to export the document PDF :/

             

            ligne 25

             

            myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);

            • 3. Re: Pick up the texte write in a specify style
              Ronald63 Level 4

              What is the text with  "page_name" ParagraphStyle ?

              • 4. Re: Pick up the texte write in a specify style
                evan71922978 Level 1

                Oh sorry I've forgot to do my DataMerge first haha

                 

                So It's fine now

                 

                Your the best !