// converts crossreference hyperlinks made for the script // updatecrossrefs to real crossreferences in CS4 // If a book is open, the book will be handled, // if no book is open, the active document will be handled. // made by Teus de Jong, latest version October 2008 if (app.books.length == 0){ if (app.documents.length == 0){ errorExit('No documents are open'); } else { nrofdocs = 1; doc = app.activeDocument; } } else { nrofdocs = app.books[0].bookContents.length; for (i = nrofdocs - 1; i > -1; i--) { if (app.books[0].bookContents[i].status != BookContentStatus.documentIsOpen) app.open(File(app.books[0].bookContents[i].fullName)); } doc = app.open(app.books[0].bookContents[0].fullName); } for (d = 1; d <= nrofdocs; d++){ NrOfHyps = doc.hyperlinks.length; if (NrOfHyps == 0){ if (nrofdocs == 1) errorExit('No hyperlinks in document'); else { if (d >= nrofdocs) break; else { doc = app.open(app.books[0].bookContents[d].fullName); continue; } } } // Make a frame with dummytext // the old hyperlink sources will be placed here // to make room for the new ones. // This strategy prevents an 'already in use' error dummyframe = doc.pages[0].textFrames.add(); dummyframe.geometricBounds = [0, 0, '50mm', '60mm']; dummyframe.contents = 'dummy'; dummychar = dummyframe.characters[0]; // use a format with only the page number try{ fmt = doc.crossReferenceFormats.item('PagNr'); } catch(e) { } if (fmt == null){ fmt = doc.crossReferenceFormats.add( 'PagNr'); fmt.buildingBlocks.add(BuildingBlockTypes.pageNumberBuildingBlock); } try{ for (i = 0; i < NrOfHyps; i++){ hyper = doc.hyperlinks[i]; // leave ID's own internal markers alone if (hyper.name.substring(0, 1) == '.') continue; hypersrc = hyper.source; // continue if the source is already a crossreference source if (hypersrc.constructor.name == 'CrossReferenceSource') continue; // leave hyperlinks to URLs alone || quit if hyperlink has no destination try { if (hyper.destination.constructor.name == 'HyperlinkURLDestination') continue; } catch (e) { hyper.showSource(); errorExit('Selected hyperlink has undefined destination'); } txt = hypersrc.sourceText; // point to another place to prevent 'already in use' error hyper.source.sourceText = dummychar; // make new crossreference source srcname = doc.hyperlinks[i].name+'_crs'; crefsrc = doc.crossReferenceSources.add(txt, fmt, {hidden:true, name:srcname}); // make the source of the hyperlink this new crossreference Source hyper.source = crefsrc; //remove the old source hypersrc.remove(); } } finally { dummyframe.remove(); } if (d >= nrofdocs){ break; } doc = app.open(app.books[0].bookContents[d].fullName); } function errorExit(s){ alert(s); exit(); }