{"id":28,"date":"2018-02-23T19:22:57","date_gmt":"2018-02-23T19:22:57","guid":{"rendered":"http:\/\/jeff-walden.com\/blog\/?p=28"},"modified":"2022-11-17T20:16:35","modified_gmt":"2022-11-18T04:16:35","slug":"creating-file-to-file-html-cross-references-in-adobe-indesign-books","status":"publish","type":"post","link":"http:\/\/jeff-walden.com\/blog\/2018\/02\/23\/creating-file-to-file-html-cross-references-in-adobe-indesign-books\/","title":{"rendered":"Creating File-to-File HTML Cross-References in Adobe InDesign Books"},"content":{"rendered":"<p>You can use Adobe InDesign to output cross-references in both PDF and HTML files and maintain both outputs using the same source material.<\/p>\n<p>Adobe InDesign does an exceptional job of helping you create file-to-file cross-references when you prepare a book for export to PDF. InDesign also does a creditable job of automatically outputting an HTML file and a CSS, although you must do this output file-by-file, even when you\u2019ve gathered these files together into an InDesign book.<\/p>\n<p>One of the things that InDesign <em>does not do<\/em> is preserve those PDF cross-references when you output the file to HTML. Adobe states this up front. I had no illusions on this matter.<!--more--><\/p>\n<p>Output a .indd file that contains a cross-reference as HTML, and you\u2019ll see HTML code that looks something like this:<\/p>\n<p><code>&lt;p class=\"paragraphs_paragraph-std\"&gt;&lt;a href=\"\"&gt;<br \/>\n&lt;span class=\"bold\"&gt;GetData&lt;\/span&gt;&lt;\/a&gt;<\/code><\/p>\n<p>That empty <code>&lt;a href=\"\"&gt;<\/code> is what remains of the cross-reference bookmark, and that spanned-and-bold <em>GetData<\/em> is the text of the linked paragraph \u2014 in this case, a level-1 head that began the file that was being linked-to. It also happened to be the name of the target file.<\/p>\n<p>Why Adobe could not fill the href with the filename + .html is a design decision on their part, and I won\u2019t debate it.<\/p>\n<p>But I can show you how to get around it.<\/p>\n<h2>It\u2019s a Big Book<\/h2>\n<p>I created a substantial API document for a client, consisting of over 100 files, plus table of contents and a multi-page index. The document is loaded with &#8220;See Alsos&#8221; implemented as cross-references, each \u201cSee Also\u201d pointing at a separate file. The guide was acceptable as a PDF, but the client wanted an HTML rendition of the same document. As is generally customary, all the HTML files would live in the same directory, and the CSS would live in a different directory at the same hierarchical level as the HTML files. I had no control over where in their server structure the client would choose to put the HTML and CSS \u2014 only the relationship of one to the other.<\/p>\n<p>The issue was how to create the hyperlinked cross-references between HTML files living in the same directory \u2014 all those &#8220;See Alsos.&#8221;<\/p>\n<h2>InDesign Already Creates HTML Hyperlinks<\/h2>\n<p>After confirming that InDesign does not output cross-references as usable links and only as empty hrefs, I turned to InDesign\u2019s Hyperlinks window.<\/p>\n<figure id=\"attachment_27\" aria-describedby=\"caption-attachment-27\" style=\"width: 571px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" class=\"size-full wp-image-27\" src=\"http:\/\/jeff-walden.com\/blog\/wp-content\/uploads\/2018\/02\/hyperlinks.png\" alt=\"InDesign Hyperlinks window\" width=\"571\" height=\"427\" srcset=\"http:\/\/jeff-walden.com\/blog\/wp-content\/uploads\/2018\/02\/hyperlinks.png 571w, http:\/\/jeff-walden.com\/blog\/wp-content\/uploads\/2018\/02\/hyperlinks-300x224.png 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><figcaption id=\"caption-attachment-27\" class=\"wp-caption-text\">Adobe InDesign Hyperlinks window<\/figcaption><\/figure>\n<p>The window is intended as a way for you to insert a hyperlink into a PDF, and it has some restrictions on the choices in the Link To pulldown.<\/p>\n<ul>\n<li><strong>URL<\/strong> \u2014 Requires a fully qualified URL. That is, it prefixes your file name with <code>http:\/\/<\/code> and produces an <code>&lt;a href=<\/code> in the HTML file. This choice is meant to link to a website, not to a web page. In my case, I couldn\u2019t dictate that each file from the book have its own URL or dictate the structure from <code>http:\/\/<\/code> down.<\/li>\n<li><strong>File <\/strong>\u2014 Produces an <code>&lt;a href=<\/code> in the HTML file that links to a file on the local machine or server. It prefixes the file name with a full pathname. (C:\\users\\documents, etc.).<\/li>\n<li><strong>Email<\/strong> \u2014 Is inappropriate to my purpose of linking one HTML file to another.<\/li>\n<li><strong>Page, Text Anchor <\/strong>\u2014 Both link to a .indd document, not an HTML file.<\/li>\n<li><strong>Shared Destination<\/strong> \u2014 While the help system states that this selection will allow you to link to any document, my experiments showed that it would link only to any .indd document.<\/li>\n<\/ul>\n<p>I tested the URL output because it produced the least and most regular file prefix \u2014 just http:\/\/ rather than a full (and varying) pathname. Its output still included that pesky http:\/\/<\/p>\n<p><code>&lt;p class=\"paragraphs_paragraph-std\"&gt;&lt;a href=\"http:\/\/test_link.html\"&gt;<br \/>\n&lt;span class=\"Hyperlink\"&gt;Test Link&lt;\/span&gt;&lt;\/a&gt;&lt;\/p&gt;<\/code><\/p>\n<h2>Light Dawns Over Marblehead<\/h2>\n<p>There were several hundred cross-references in the whole document, but I could manually duplicate each one with a URL Hyperlink. It would be the work of a day or so, but once done, all those links would be in place.<\/p>\n<p><strong>Note:<\/strong>&nbsp;There may be a script way of duplicating the cross-references with Hyperlinks; I didn&#8217;t spend the time trying to create one. Doing this process manually also allowed me to see if there were any cases where my method wouldn\u2019t work for me. I didn&#8217;t find any.<\/p>\n<p>By good fortune, I had adopted a file naming convention for the book that began each file name with api_. Thus, each hyperlink that InDesign would create would be in the form<\/p>\n<p><code>&lt;a href=\"<a href=\"http:\/\/api_getdata\">http:\/\/api_getdata<\/a>.html\"&gt;GetData&lt;\/a&gt;<\/code><\/p>\n<p>I could do a search-and-replace on the exported HTML files in Dreamweaver for <code>&lt;a href=\"<a href=\"http:\/\/api_\">http:\/\/api_<\/a> <\/code> and replace it with <code>&lt;a href=\"api_<\/code><\/p>\n<p>Doing this:<\/p>\n<ul>\n<li>Removed the problem of InDesign\u2019s insertion of the http:\/\/<\/li>\n<li>Would not remove any http:\/\/ links that really had to be there (they would not be followed by api_)<\/li>\n<li>Would let html file call html file within the same directory without a fully qualified URL<\/li>\n<li>Would not dictate where in the directory structure the files had to be located.<\/li>\n<\/ul>\n<h2>Conditional Text<\/h2>\n<p>Now I had two sets of links in each document \u2014 conventional cross-references and Hyperlink references. I created two text conditions, PDF and HTML, and applied the conditions to the appropriate links.<\/p>\n<p>With two document conditions, I could switch on PDF links for PDF output, and HTML links for HTML output, and I could maintain both sets of links in the same source material. I could remove the unused http:\/\/ in Dreamweaver during post-production, and the resulting HTML version of the book was hyperlinked in much the same way that the built-in cross-references created for PDFs.<\/p>\n<h2>TOC and Index<\/h2>\n<p>This client\u2019s document is a work in progress, but it appears that the table of contents may be amenable to removing the http:\/\/ from &lt;a href=&#8221;http:\/\/api_\u2026 but the index is a <em>much<\/em> more gnarly problem. The hrefs in the index are individual page numbers. This makes sense, because in a PDF index, it is the page numbers that are hyperlinked, not the indexed topics. I\u2019m not sure yet whether there is any reasonable automated way to replace the page numbers with HTML bookmarks. My project may need to go without its index for now.<\/p>\n<h2>Stylesheet Issues<\/h2>\n<p>This HTML cross-reference method requires post-processing of the HTML files to remove the http:\/\/, but it also requires post-processing for stylesheet use. InDesign\u2019s HTML output process creates a directory for each file called &lt;filename&gt;-web-resource. In that directory is a directory named CSS, and in the CSS directory, the export process puts a stylesheet named idGeneratedStyles.css based on the styles from your InDesign stylesheet.<\/p>\n<p>All my pages use the same InDesign stylesheet definitions; but not every page uses all styles. Consequently, the idGeneratedStyles.css varies from exported file to exported file depending on which styles the file used.<\/p>\n<p>After I exported the first file, I copied idGeneratedStyles.css to a CSS directory and renamed the file main.css.<\/p>\n<p>In succeeding exports, I used the HTML export dialog box to tell InDesign both to generate a stylesheet from the styles used on the page and to use main.css. (In future output, I won\u2019t need to do that; the files will just use main.css.)<\/p>\n<p>I found that the export process <em>copied<\/em> the pre-existing main.css to the &lt;filename&gt;-web-resource folder and linked to it there rather than link to its original location. I had to make sure that I made any changes to the main.css stylesheet I was building, and not the main.css stylesheet that export had copied into the web-resources directory. I wanted one main.css file for all files to access.<\/p>\n<p>As I exported each succeeding file, in the browser I could see the styles that main.css did not already include. I added those styles from idGeneratedStyles.css to main.css. Thus, main.css slowly accumulated the definitions required by each export and made them available for use in all the files. Before I left it, I modified each HTML file to point only to main.css.<\/p>\n<p>In future HTML outputs, I will have to search-and-replace the link to the generated stylesheet and re-point it at main.css. There does not seem to be any good way to overcome InDesign\u2019s practice of copying main.css into the web-resources directory. However, after working through the book file-by-file, I won&#8217;t have to go through the process of accumulating definitions in main.css (unless, for some reason, I add new definitions).<\/p>\n<h2>Conclusion<\/h2>\n<p>Admittedly, this is a work-around that requires duplicating the built-in cross-references as hyperlinks and setting up conditional text to switch between the two sets. It requires post-processing handwork once during the initial HTML output, and later (much more minimal handwork) whenever the HTML files need to be re-generated or new ones added. But the method does achieve a result that Adobe says InDesign does not do \u2014 output HTML hyperlinked cross-references to HTML files.<\/p>\n<p>By building the duplicate links and conditions into the files as the files are written, and planning for the post-processing time needed to build a single CSS file, you can use InDesign to output both PDF and HTML and maintain both outputs using the same source material.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use Adobe InDesign to output cross-references in both PDF and HTML files and maintain both outputs using the same source material. Adobe InDesign does an exceptional job of helping you create file-to-file cross-references when you prepare a book for export to PDF. InDesign also does a creditable job of automatically outputting an HTML [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,3,12],"tags":[13,14],"_links":{"self":[{"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/posts\/28"}],"collection":[{"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":3,"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":78,"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions\/78"}],"wp:attachment":[{"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/jeff-walden.com\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}