10 Replies Latest reply on Sep 9, 2009 2:09 AM by Anitha Selvaraj

    How to duplicate pages effectively

    Anitha Selvaraj Level 2

      Hi all,

       

      we want to create 1000 page document from a single page template, hence we create pages using duplication.

      "for (var i=1; i<noOfPages; i++){
              myDocument.pages.item(0).duplicate(LocationOptions.AT_END,myFirstPage);   
          }"

      During debugging we found the page creation time increases linearliy with increase in page

      ie creation of page is as following

      1st - 1sec

      2nd - 1sec

      3rd - 1sec

      .

      .

      .

      10th - 3sec

      .

      .

      .

      100th-40sec.

       

      Is there an alternate approach to acheive the above work ?

        • 1. Re: How to duplicate pages effectively
          Harbs. Level 6

          First of all, it should be:

               

          myDocument.pages.item(0).duplicate(LocationOptions.AFTER,myFirstPage);

           

          About your problem:

           

          You need to clear the undo stack. Doing a "save as" every once in a 

          while does the trick.

           

          Harbs

          1 person found this helpful
          • 2. Re: How to duplicate pages effectively
            Anitha Selvaraj Level 2

            Thanks Harbs,

             

            But hw to disable Undo ?

            • 3. Re: How to duplicate pages effectively
              Harbs. Level 6

              You can't disable it. Doing a "save-as" clears it.

               

              Harbs

              1 person found this helpful
              • 4. Re: How to duplicate pages effectively
                Anitha Selvaraj Level 2

                Iam trying to create a document dynamically with n number of pages using

                myDocument.pages.item(0).duplicate(LocationOptions.AFTER,myFirstPage);

                 

                The above code loops through till all the empty pages are created.

                 

                The execution time for each duplication takes around 2-3 sec at the very beginning and increases linearly.

                 

                So if there are 500 pages... then the server response is very bad.. is this because of the undo/redo stack?

                • 5. Re: How to duplicate pages effectively
                  Harbs. Level 6

                  Use doc.documentPreferences.pagesPerDocument = yourNumber

                   

                  Harbs

                  • 6. Re: How to duplicate pages effectively
                    Anitha Selvaraj Level 2

                    Still the performance is same ...

                    • 7. Re: How to duplicate pages effectively
                      Harbs. Level 6

                      Huh?

                       

                      That should add all the pages at once. There should not be any 

                      performance problems at all.

                       

                      Harbs

                      • 8. Re: How to duplicate pages effectively
                        Anitha Selvaraj Level 2

                        Thanks for all your quick responses.

                        We feel are creating the pages in the following way

                         

                        function createPages(noOfPages){
                            myDocument.documentPreferences.pagesPerDocument = noOfPages;
                            for (var i=1; i<noOfPages; i++){
                                myDocument.pages.item(0).duplicate(LocationOptions.AFTER,myFirstPage);   
                                alert ("--page number "+ i);
                            }   
                        };

                         

                        Is this the correct way of creation or we missing something ?

                        • 9. Re: How to duplicate pages effectively
                          Harbs. Level 6

                          No. You are creating the pages twice (i.e. double your desired number 

                          of pages.

                           

                          Once you set the number of pages using pagesPerDocument, you don't 

                          need your loop at all.

                           

                          Harbs

                          • 10. Re: How to duplicate pages effectively
                            Anitha Selvaraj Level 2

                            // Main Script

                            try{

                                            // We have template with one page

                                            var myDocument = app.open (templateName, true);

                            ..

                                            // Read a xml file of fetches the values which are substituted into the template like text and images

                                            ..

                            createPages(noOfPages); // We have found the number pages to be generated

                                            placePageFooterElements(noOfPages);

                            ..

                                            // Finally export  the document into pdf format

                            }

                            catch(e){

                                            logError(e + ": ERROR" );

                                            throw(e);

                            }

                             

                            function createPages(noOfPages){

                                            Scenario 1:

                                            // If I create document using the below script I get error during [pageTextFrames.itemByName("pageNo").associatedXMLElement.xmlElements as undefined - placePageFooterElements(noOfPages)]

                                            myDocument.documentPreferences.pagesPerDocument = noOfPages;              

                            };

                            function placePageFooterElements(noOfPages){

                                            for (var pageNo=0; pageNo<noOfPages; pageNo++){                    

                                                            //Assigning labels for all imageFrames and textFrames - label will be same as that of markupTagName

                                                            //for imageFrames

                                                            alert ("---pageNo---"+pageNo);

                                                            var pageImageFrames = myDocument.pages.item(pageNo).rectangles;

                                                            for(var l=0;l<pageImageFrames.length;l++) {                                                                                                      

                                                                            try {

                                                                                            pageImageFrames.item(l).label = pageImageFrames.item(l).associatedXMLElement.markupTag.name;

                                                                            }catch(e) {                                                          

                                                                            }

                                                            }//end of pageimageFrames loop

                                                           

                                                            //for textFrames

                                                            var pageTextFrames = myDocument.pages.item(pageNo).textFrames;

                                                            for(var l=0;l<pageTextFrames.length;l++) {                                                                                                          

                                                                            try {

                                                                                            pageTextFrames.item(l).label = pageTextFrames.item(l).associatedXMLElement.markupTag.name;

                                                                            }catch(e) {

                                                                            }

                                                            }//end of pageTextFrames loop               

                                           

                                                            //placing pageFooter elements

                                                                            pageTextFrames.itemByName("pageNo").associatedXMLElement.xmlElements.item("currentPage").c ontents = String(pageNo +1);

                                                            pageTextFrames.itemByName("pageNo").associatedXMLElement.xmlElements.item("totalPages").co ntents = String(noOfPages);

                                                           

                                                            pageTextFrames.itemByName("userId").contents = userName;

                                                            pageTextFrames.itemByName("printedDate").associatedXMLElement.xmlElements.item("dateCreate d").contents

                                                                                                            = String(date.getMonth() + 1) + "-" + String(date.getDate()) + "-" + String(date.getFullYear());          

                                                           

                                                            pageTextFrames.itemByName("pageBody").strokeWeight = 1;

                                                            pageTextFrames.itemByName("pageBody").strokeColor = myDocument.swatches.item("c0m0y0k80");               

                                                            pageTextFrames.itemByName("pageHeader").strokeWeight = 1;

                                                            pageTextFrames.itemByName("pageHeader").strokeColor = myDocument.swatches.item("c0m0y0k80");               

                                                            pageTextFrames.itemByName("pageFooter").strokeWeight = 1;

                                                            pageTextFrames.itemByName("pageFooter").strokeColor = myDocument.swatches.item("c0m0y0k80");               

                                            }             

                            };