8 Replies Latest reply on Jun 1, 2011 1:28 AM by John Hawkinson

    Fastest way to duplicate page


      We have a course template with 2 pages in it. We count the number of nodes in the XML data and duplicate these 2 pages and then import the XML so the xml data would fill the placeholders.


      The issue is that some of the XML data is large which requires a number of pages to be created (duplicated). Some xml data files need 500 pages created (duplicated) which takes a very long time.


      What is the fastest way to duplicate a page? The method we're using is page.Duplicate().Move(idLocationOptions.after, prevPage);

        • 1. Re: Fastest way to duplicate page
          John Hawkinson Level 5

          How about using Data Merge with empty fields?

          • 2. Re: Fastest way to duplicate page
            xmlapi Level 1

            Can't use data merge.


            Creating 300 pages takes almost forever. Is there anyway to speed this up?


            Page firstPage = doc.Pages[1];

            for(int i=0; i < 300; i++)


                 doc.Pages[i].Duplicate().Move(idLocationOptions.idAfter, firstPage);


            • 3. Re: Fastest way to duplicate page
              John Hawkinson Level 5

              Why not? Again, don't use Data Merge for your data. Just use it to create all the pages.

              • 4. Re: Fastest way to duplicate page
                xmlapi Level 1

                Basically, in my template I have 3 pages.


                First page is TOC page.


                Second and Third page are course pages containing the "xml structure" for xml import.


                When I data merge it, I want it to "duplicate" those second and third pages for each xml node.


                I created a sample csv file containing the records:







                Then I set the data source to the csv file....so how do I know tell the data merge to just create the course pages?



                Alternatively, I can do this to duplicate the pages which seems VERY fast. HOWEVER, how do I set the geomtric bounds and the xml structure? Each of those page items has an xml element associated with it.


                     for (int i = 0; i < 300; i++)
                              Page newPage = doc.Pages.Add(idLocationOptions.idAtEnd, Type.Missing);
                                foreach(dynamic a in leftPage.AllPageItems)

                • 5. Re: Fastest way to duplicate page
                  Harbs. Level 6

                  I'd probably do it something like this:


                  doc.documentPreferences.pagesPerDocument = 303;


                  //group the page items


                  //loop thorugh the addedPages


                  //ungroup as necessary...


                  FWIW, I avoid InDesign XML like the plague. I've had too many bad experiences with it. I use standard InDesign objects and I process xml using scripting and E4X instead.



                  • 6. Re: Fastest way to duplicate page
                    xmlapi Level 1

                    I tried this:


                    Document a = OpenCourseTemplate();
                                a.DocumentPreferences.PagesPerDocument = 303;


                                Page page = doc.Pages[2];
                                Group g = doc.Groups[1]; //The grouped textframes on page 1
                                for(int i=3; i < doc.Pages.Count; i++)
                                    Page a= doc.Pages[i];
                                    g.Duplicate(a, Type.Missing);
                                doc.Save(Utility.MergedFolder + "\\test_size.indd");


                    It doesn't work because        g.Duplicate(aa, Type.Missing); throws a return argument has an invalid type exception.


                    Any idea why it doesn't work?

                    • 7. Re: Fastest way to duplicate page
                      xmlapi Level 1

                        doc.DocumentPreferences.PagesPerDocument works perfectly!


                      The only problem is that I need these blank pages created BETWEEN page 1 and 2. Is there any options I can specify for this to happen?

                      • 8. Re: Fastest way to duplicate page
                        John Hawkinson Level 5

                        There are not so many questions here that it is helpful for you to ask your tangential questions in a new thread. I would venture to say that it probably will make it harder for you to get answers if you do that.


                        p.s.: you could try moving page 2 to page 52.