6 Replies Latest reply on Mar 21, 2017 5:28 AM by Kasyan Servetsky

    Merging multiple documents into one, but losing cross-references

    lilis_skyremix

      Hi,

       

      I'm trying to merge several INDD documents into one editable INDD document. Moving pages is easy, with the Page panel and Move order.
      However, the cross-references for cross-documents go haywire after I move it, losing destinations and such.

       

       

      Is there a way (or a script) that could merge all documents into one and update the cross-references for the new (single) document?
      I'm losing several of hours of worktime since we have to manually adjust it.

       

       

      Any help would be greatly appreciated.

      Thank you.

        • 1. Re: Merging multiple documents into one, but losing cross-references
          Eric Dumas Adobe Community Professional

          Hi,

          have you considered creating a book instead of merging the pages?

          • 2. Re: Merging multiple documents into one, but losing cross-references
            Kasyan Servetsky Level 5

            Yes. it's possible to solve this issue by scripting. I just wrote a couple of scripts. Going to post them here with explanation and sample files.

            — Kas

            • 3. Re: Merging multiple documents into one, but losing cross-references
              Kasyan Servetsky Level 5

              First of all, let’s look under the hood to see what happens when we make cross-references in InDesign.

              Here I posted the sample files and scripts used in the testing described below.

              I created a new document Test-1.indd and added three anchor points using the default names offered by InDesign: Anchor 1, Anchor 2 and Anchor 3. Then I created three cross-references pointing to them.

               

              20-03-2017 18-08-40.png

              Finally, I duplicated resaved the file as Test-2.indd

               

              From the scripting point of view, cross-reference (which we see in the cross-references panel) is a variety of the hyperlink object. Hyperlink contains two other objects: destination and source. All the three have names which are generated by InDesign.

              20-03-2017 13-17-34.png

              Let’s open Test-1.indd and run this script. (List hyperlink names.jsx)

              Main();
              
              function Main() {
                  var hyperlink,
                  str ="",
                  doc = app.activeDocument,
                  hyperlinks = doc.hyperlinks;
                  
                  for (var i = 0; i < hyperlinks.length; i++) {
                      hyperlink = hyperlinks[i];
                      str += "#" + (i + 1) + " - Hyperlink: " + hyperlink.name + ", destination: " + hyperlink.destination.name + ", source: " + hyperlink.source.name + "\r";
                  }
              
                  alert(str);
              }
              

              We see that InDesign uses some default base names adding incrementing numbers at the end.

              20-03-2017 18-39-28.png

              Now let’s cut the text frame from Test-1.indd, paste it into Test-2.indd (note it has six cross-references now) and run the script again.

              20-03-2017 18-47-53.png

              Note that InDesign automatically resolved the conflict – both documents had the same set of cross-references using exactly the same names – by adding next available order numbers.

              Here’s the root of the problem: when we move text/pages to another document, cut/copy-paste text, rename files, etc. the names can be changed and in turn destinations can be lost.

               

              My idea of solving it is as follows:

              Before making any manipulations, which can break cross-references – e.g. moving pages to another document – we run a script which generates a unique name (13-14 digits) and renames each cross-reference (in scripting terms: hyperlink, destination and source).

              When cross-references get broken, we open all the documents and run another script which loops through them fixing broken cross-references which it finds by unique names.

               

              Let’s illustrate this with an example:

              I created a test file -- Starting Point.indd -- with 15 cross-references. Note the default names

              20-03-2017 19-16-09.png

              Now I run the Rename cross-references script: all names are unique numbers (Renamed xRefs.indd)

              20-03-2017 19-03-41.png

              Now I move each page to another document and open them all, all cross-references are OK (green circle) so far.

              20-03-2017 19-17-05.png

              But if I close and rename the files, or move them to other folders, they become corrupted.

              20-03-2017 19-16-35.png

              Finally, I run the Fix cross-references script and all the cross-references become normal again.

               

              Of course, this doesn't handle a situation when a few cross-references point to the same destination, but this also can be handled by script: off the top of my head: the first script may create a txt/csv file listing the pairs cross-reference—destination, the second one may read it to restore broken cross-references.

               

              Regards,
              Kas

              1 person found this helpful
              • 4. Re: Merging multiple documents into one, but losing cross-references
                lilis_skyremix Level 1

                It originally is a book, but needs to be merged for other purposes.

                • 5. Re: Merging multiple documents into one, but losing cross-references
                  lilis_skyremix Level 1

                  First of all, thank you for posting with such kindness. I'll try the scripts you've shared, and hope for the best.

                  I'll come back with the results. Thanks again!

                  • 6. Re: Merging multiple documents into one, but losing cross-references
                    Kasyan Servetsky Level 5

                    However I can't promise it will work for you since I haven't seen your files and have no idea what settings you use for creating your cross-references and what happens to them after data merge.

                    — Kas