7 Replies Latest reply on Jun 19, 2013 12:13 PM by shilpa25

    Naming PDF using para.style applied

    shilpa25 Level 1

      Hi Forum!

       

      Could any body tweak on this script.please.

       

      while runnig this script, i could able to export PDF. The pdf naming will be the contents inside the document on everypage, on which paragraphStyle "Title" is applied.

       

      The problem is, if the pargraphStyle "Title" is applied twice a time in a same page, the pdf is produced twice a time for the same page likewise so on.

       

      eg. The paragraphStyle "Title" is applied for the content "XYZ" on page 1, and for the content "123" on page 2.

       

      Result of this 4 pdf are produced. XYZ_1.pdf, XYZ_2.pdf and 123_1.pdf adn 123_2.pdf..  My necessary is to have pdf produced only one time for a content which has "Tittle" paragraphstyle applied.

       

      app.findGrepPreferences = null;

      app.findGrepPreferences.appliedParagraphStyle = "Title";

       

      result = app.activeDocument.findGrep();

       

      while (result.length)

      {

         str=result.pop();

       

       

      var myDoc = app.activeDocument;

      app.findGrepPreferences = NothingEnum.nothing;

      app.findGrepPreferences = NothingEnum.nothing;

        app.findGrepPreferences.findWhat =str.contents;

       

      var myFind  = myDoc.findGrep();

      for(var a=myFind.length-1; a<=0; a++){

       

           myFinds = myFind[a];

           }

      for(var myCounter = 0; myCounter < myDocument.pages.length;

      myCounter++){

      myPageName = myDocument.pages.item(myCounter).name;

      app.pdfExportPreferences.pageRange = myPageName;

       

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

      myPageName = myPageName.replace(myRegExp, "_");

      myFilePath = myFolder + "/" + myFinds.contents + "_"+ myPageName + ".pdf";

      myFile = new File(myFilePath);

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

      }

        • 1. Re: Naming PDF using para.style applied
          shilpa25 Level 1

          Hi Forum,

           

          I have tried in many ways, but still i could get PDF for each and every find.as a seperate PDF.

           

          My request is to export PDF only the first instance of the "find out text".

           

          eg. if "XYZ" is the content on Page1 and paragraphStyle "Title" is applied to it and "123" on page 2 with the same paragraph style "title" applied.

           

          The PDF should be produced only one time for the content XYZ and 123. Currently the above script produces, 2 PDFs for the searched out content XYZ and 2 PDFs for the content 123. (but the content XYZ is not on Page 2).

           

          Any help please.

          • 2. Re: Naming PDF using para.style applied
            Vamitul Level 4

            actualy your script's logic is wrong from start to end.

            it searches for all the text in the document that has the "Title" pstyle applied.

            Then, for every found item it exports EVERY page form the document as PDF naming it found_nr.pdf

             

            so, for example if your document has 100 pages, and you have the title pstyle applied on page 1 and again on page 50, you will get 100 PDF's named titleOnPageOne_nr.pdf, and 100 pages named titleOnPage50_nr.pdf

             

            your script should work like this

            1) get the first title (what happenes if there is no titile on page 1?), save it in a variable myName

            2) for every page

            for(var myCounter = 0; myCounter < myDocument.pages.length;

            myCounter++)

            {

            3) on that page, test if there is a title (if there are 2 titles, in two different frames, wich one will be considered the page name? The first found? The top most? etc)

            4) if it exists, set myName to it.

            5) save your PDF page as before

            }

            1 person found this helpful
            • 3. Re: Naming PDF using para.style applied
              shilpa25 Level 1

              Hi Vam,

              thanks for your advise and feedback...

               

              I'm trying to do the task and still confusion in stopping the loops after every found and then export to pdf.. As i m not profound in doing such a complicated script, I'm striving to do it..

              It would be a great help to me, if you can modify this script. please..

               

              thanks

              shil...

              • 4. Re: Naming PDF using para.style applied
                shilpa25 Level 1

                Help Forum,

                 

                 

                glad to receive the solution.

                 

                I had a try, but still could produce the same for every title for every page.

                 

                thanks in advance.

                • 5. Re: Naming PDF using para.style applied
                  shilpa25 Level 1

                  Atlast I found out, the only thing i need is, if the same style repeated in other page, the pdf is overrited. as per Vam's advice.

                   

                  So how can i solve this.. Please

                   

                  for(var p = 0; p < app.documents[0].pages.length; p++) {

                       var fr = app.documents[0].pages[p].textFrames;

                       var pdf_name = null;

                   

                   

                       for(var i = 0; i < frames.length; i++) {

                            if(fr[i].paragraphs[0].appliedParagraphStyle.name == 'Cover Heading-White') {

                                 pdf_name = fr[i].paragraphs[0].contents;

                                break;

                            }

                       }

                   

                   

                       if(pdf_name != null) {

                            app.pdfExportPreferences.pageRange = app.documents[0].pages[p].name;

                   

                   

                            var export_preset = app.pdfExportPresets.item("[Smallest File Size]");

                   

                   

                            app.activeDocument.exportFile(ExportFormat.pdfType, File("/Users/xxxx/Desktop/Local/untitled folder/" + pdf_name + ".pdf"), false);

                       }

                  }

                   

                   

                  thanks a lot for VAM's clue and suggestion.

                  • 6. Re: Naming PDF using para.style applied
                    Vamitul Level 4

                    Shilpa, congratulations!

                     

                    your problem is easily fixed by adding the page number to the pdf name:

                      app.activeDocument.exportFile(ExportFormat.pdfType, File("/Users/xxxx/Desktop/Local/untitled folder/" + pdf_name+"_"+p.toString()+ ".pdf"), false);

                     

                     

                    as much as possible, avoid using the break statement (unless you are using it in a "switch" statement).

                    • 7. Re: Naming PDF using para.style applied
                      shilpa25 Level 1

                      thanks VAM.

                       

                      And also i'm trying to get the pages without the "tile" header, exported within thescript.

                       

                      thanks for the support VAM....

                       

                      your hint saves my time lot.

                       

                      Shil....