In the last two blogs I demonstrated how easy it is to create a simple ePub publication. In short, this involved using scripts to help with some of the processes for creating the document, placing images, and importing text. To insure that the finished document exports correctly, we followed a few simple rules:

  • Use a template or document preset to establish page parameters.
  • Import styles from a stylesheet for styling text, objects, tables, and colors.
  • Use these styles exclusively for styling text, objects, tables, and colors.
  • For images that flow with the text you must anchor the images.
  • For free-standing images, use the Articles panel to determine its location within the document export.

When you export your document for ePub, a package is created that contains all of the resources for the ePub. If you were to crack this package open, you would find a single HTML file for the document and one for the cover if you included one.

Now for the Hard Part

Now that you can create a simple ePub file, we will add one little level of difficulty: chapters and indexing. The following discussion is for the Creative Cloud (CC) version of Adobe InDesign. The procedure for working with other versions 5.5 and above are simiar. If using CC you will appreciate the improvements made for chapter and table of content support.

Chapters

Of course you want each chapter in your book to start on its own page. To do this, each chapter, as well as the cover and table of content page, will need to be saved out as their own separate HTML file. But don’t fret, you can let Adobe InDesign do the heavy lifting for this process.

The key is in the paragraph style applied to the first paragraph of each chapter. This paragraph style must be unique. In other words, it cannot be used anywhere in your book other than to style the first paragraph of each chapter. With paragraphs so styled, you tell the ePub export process to split the document wherever the style is found. There are several ways this can be done:

  • In the Export Tagging panel for Paragraph’s Style Options, check the checkbox next to Split Document (EPUB only) and select Based on Paragraph Style Export Tags in the Split Document field drop down in the EPUB Export Options, Advanced panel.
  • In the EPUB Export Options, Advanced panel, select the paragraph style from the drop down for the Split Document field.

The first option makes it possible to have more than one paragraph style act as a page break. The second option gives more flexibility if only one style is used to split the document. With this option, your stylesheet does not have to designate which style will be used to spit the document. The designation is established during the export process.

But before you export, you need to set up your Table of Contents.

Table of Contents

Hopefully, you planned for your table of contents when you created your stylesheet. You can save several styles in your stylesheet to serve your every need. But try to standardize on the names you use for your paragraph styles. We use “Chapter_Head” and “Chapter_Title” for our chapter’s first paragraph styles and “Chapter” for the container’s object style. The next style property for “Chapter_Head” is “Chapter_Title”. The next style property for this style is “First,” and “First” has “Body” for its next style. We set the “Chapter” object style up to use “Chapter_Head” for its paragraph style with Apply Next Style checked. This way our script can style the text automatically when imported.

For our sample table of contents we created three paragraph styles for styling its headline and entries: TOCTitle, TOCLevel1, and TOCLevel2. Then in setting up our Table of Contents style (Layout > Table of Contents Styles), we selected TOCTitle to style the Title. As we only wanted to reference the chapter and chapter title in our table of contents, only these two entries were moved from the Other Styles panel into the Include Paragraph Styles list. We then applied the TOCLevel1 style to our Chapter_Head reference and TOCLevel2 to our Chapter_Title reference. If you have not done this before, notice that when you click on the name of the paragraph style in the Include Paragraph Styles list, the title for the Style field below changes. Disclose this field’s drop down and choose the appropriate paragraph style for the entry. Repeat for the remaining style entries.

Before saving the table of contents style, we also made sure that Make text anchor in source paragraph was checked. This option sets up a hyperlink for each entry to its paragraph in the text.

When you create your table of contents (Layout > Table of Contents), you will need to click the loaded cursor onto a new page at the front of your book. Notice that page numbers are included with the entries and even show up when previewed with Adobe Digital Editions. Thankfully, these disappear nicely when the ePub is uploaded to the iPad.

If you were to expand this ePub package, you would now see that there is an HTML file for each chapter as well as one for the cover (if included), and one for the table of contents.

Automating the Process

To automate the Table of Contents process, make sure the stylesheet you use has the necessary paragraph and Table of Contents styles. For your CreateEPubDocument script, add a checkbox field to the script’s custom dialog to give the user the option to import table of content styles. Add the appropriate code to import the styles if the checkbox is checked. We have updated our sample script to demonstrate how this can be accomplished.

On Your Own

Try our sample CreateEPubFromPreset script with the sample stylesheet included in the download. (See this site’s AppleScript and ExtendScript pages.) Make sure you have a document preset set up for the page size you want for your document. Don’t forget to set its Intent to Web. Remember that margins and columns don’t make much sense when setting up a document for ePub. As, with few exceptions, everything conforms to the margins set as part of the ePub Export process.

Off Topic

Create Now World Tour may be coming to your area soon. Starting on September 19 in San Francisco, the tour is scheduled for 13 cities across North America. Events are free and provide attendees with an opportunity to meet and learn from experts. For more, see bit.ly/CreateNowCom.