ePub


Creating ePub Documents With Scripts II

Tuesday, January 08, 2013

In our previous blog we introduced you to a little script "EPubDocFromPreset." The script (written in both AppleScript and ExtendScript) is available for download from the EPub page at yourscriptdoctor.com.

The bulk of the script is a user dialog for acquiring the information for the project from the user. The first field in the dialog is for the name of the project. If style sheets are made available, the user has the option to select a stylesheet from which to download paragraph, object, and table styles, as well as color swatches. Once the user enters the information for the dialog, the script builds the document. I hope you were able to spend a little time with the EPubDocFromPreset script.

For this blog we add two routines to the scripts (download the updated scripts from this site's ePub page):

  • addMetadata - This routine adds the following metadata to the document:
    1. The author name
    2. The document title
    3. Copyright information

    To accommodate the routine that adds metadata to the document, we have changed the EPubDocFromPreset script to include the author name field as part of the custom dialog.

    You are welcome to add more fields to the dialog to get additional information from the user to add to the document's metadata. A description (text edit box) field might be appropriate as well as a series of checkboxes to indicate metadata keywords.


  • saveDoc - This routine saves the document created to the folderPath established in the script. This path is to a folder named the same as the project and is located in the user's Documents directory.

The name of the document is the same as the project with the .indd file name extension.

Save Doc Subroutine

Let's look at the Save Doc routine:

It requires the name of the project (from custom dialog) and a reference to the document.

AppleScript

--call to handler
saveDoc (projectName, docRef)

on saveDoc (projectName, docRef)
     --get path to documents folder in user's directory; coerce it to a string value
     set userFolder to (path to documents folder from user domain) as string
     --determine path to project folder inside user's documents folder
     set folderPath to userFolder & ":" & projectName 
     --determine name for document when saved
     set filePath to folderPath & ":" & projetName & ".indd"
     --If folder defined by folderPath does not exist have the Finder create it
     tell application "Finder"
          if not (exists folder folderPath) then
               make folder at userFolder with properties {name:projectName}
          end if
     end tell
     --have Adobe InDesign add the project name to the document's label and save
     tell application "Adobe InDesign CS6"
          set label of docRef to projectName
          save docRef to filePath
     end tell
end saveDoc

ExtendScript

--call to function
saveDoc (projectName, docRef);

//saves Document to user's document folder in folder named with projectName variable
function saveDoc (projectName, docRef) {
   //put project name in label property of document
   docRef.label = projectName;
   //determine path to project folder inside user's documents folder
   var userFolder = Folder.myDocuments;
   var folderPath = userFolder + "/" + projectName;
   //verify if folder exists; if not create it
   var checkFolder = Folder (folderPath).exists;
   if (checkFolder == false) {
        Folder(folderPath).create();
   }
   //determine name and path for document when saved
   var savePath = folderPath + "/" + projectName + ".indd";
   //save the document
    docRef.save(new File(savePath)); 
}

Notice that the subroutine sets the value of the document's label to the name of the project. This will be used to identify the path to the document's resources (inside the project folder) as part of the script we will introduce in the next blog.

Add Metadata Subroutine

Adding metadata to a document is done by adding values to the metadata preferences for the document. The script adds the publication date to the document's metadata job name.

The information for the metadata, with exception of the author's name and current date are set at the top of the script with the assumption that this information will be consistent for all projects.

Coming Next Week

In the next blog we will introduce a second script that will populate the document with an image and three paragraphs (headline, body copy, and an empty paragraph for anchoring image) for each of eight pages. Images will need to be 512 pixels wide by 400 pixels high. If you have an idea for a book you want to create, you might start by creating images named pg01.jpg through pg08.jpg. The text can be entered in a plain text file with paragraph returns after each paragraph (3 for each page). You may also want to create a cover for your book. Height to width ratio for the cover should be about 1.3 to 1. Our sample cover is 600 wide by 800 pixels high and should be considered the minimum size allowed.

Meanwhile, make sure you understand all that the script is doing. Take advantage of having a stylesheet or two available for the script in a "styles" folder. The script, as written, uses the Presets folder inside the application folder. This is identified by the variable styleFolderPath. If you (or your user) do not have administrative access, you will need to locate the style folder elsewhere on your computer. If so, you will need to change the script accordingly.

Trackback Link
http://www.yourscriptdoctor.com/BlogRetrieve.aspx?BlogID=15847&PostID=789792&A=Trackback
Trackbacks
Post has no trackbacks.