MICROSOFT WORD OR GOOGLE DOCS

Your client often gets copy from a number of people who don’t have access to Adobe InCopy. The best option then may be to have the document created in Microsoft Word or, for a collaborative workflow, have the document created in Google Docs. From within Google Docs you or your client can download the file as a Microsoft Word file.

If one of these is to be the option, you may want to make sure that whoever creates the document uses paragraph styles. In Google Docs the styles are provided from within the Format menu. The names for these default styles are Normal (for body text), Title, Subtitle and Heading 1 through Heading 6. To help, you could create a little tutorial on how to set text styling and suggest a template (or two) to choose from. That way, your InDesign templates (or styles) can be set up to correspond with the styles used by the author.

IMPORTING MS WORD FILES

To make sure a document in Microsoft Word format is imported correctly, you will want to use a script. The script can set the file import preferences as needed, massage the text, and make sure the text flows into your document as needed. The following demonstrates:

ImportMSWordFile Script

Step 1 Make sure you have a document open for placing the imported file into. We will set this up as a handler in AppleScript.

  (*Returns reference to active document; otherwise generates error.*)
   on getDocRef()
	tell application "Adobe InDesign CC 2015"
	   if modal state = true then
		error "Please close dialogs before running script"
	   end if
	   if not (exists document 1) then
		error "Requires active document"
	   else
		return document 1
	   end if
	end tell
   end getDocRef

Step 2 Call the handler from inside a try/on error trap to alert the user that a document must be open in InDesign to run the script.

   try
	set docRef to getDocRef()
   on error errStr
	activate
	display alert errStr
	return
   end try

Step 3 Have the user choose the file. When a file is downloaded from Google Docs, it is placed in the Downloads folder. For the sake of this demonstration script, we will use this as the deault location for choosing the file. Again, a handler will be used for this functionality. The call to this handler will follow that of getDocRef inside the try/on error block.

--the call
   set fileRef to chooseMSWordFile()
--the handler
   (*Returns alias reference to file chosen if Microsoft Word file*)
   on chooseMSWordFile ()
      set homeFolder to path to home folder from user domain as string
      set targetFolder to (homeFolder & "Downloads") as alias
      set fileChoice to choose file with prompt "Select Microsoft Word file to import" default location targetFolder
      set fileInfo to info for fileChoice
      if name extension of fileInfo is not in {"docx", "doc"} or kind of fileInfo is not "Microsoft Word Document" then
	error "Microsoft Word document not chosen"
      end if
      return fileChoice
   end chooseMSWordFile

Step 4 Next, set the preferences for importing a Microsoft Word file as needed. Again, a handler will be used. Make sure the settings are as you would prefer. They should be fairly standard. If there are some that may need to be set differently, you would need to create a custom dialog to allow the user to change the preference settings. The call to this handler will follow that of chooseMSWordFile above.

--the call to mWordImportPref()
   mWordImportPrefs()
--the handler
   (*Sets preferences for importing Microsoft Word RTF format.*) 
   on mWordImportPrefs()
	tell application "Adobe InDesign CC 2015"
	   set thePrefs to {use typographers quotes:true, convert page breaks:none, import unused styles:false, convert bullets and numbers to text:false, convert tables to:Unformatted Table, preserve local overrides:false, import index:true, import endnotes:true, import footnotes:true, preserve graphics:true, preserve track changes:true, resolve character style clash:resolve clash use existing, resolve paragraph style clash:resolve clash use existing, import TOC:true, remove formatting:false}
	   set properties of word RTF import preferences to thePrefs
	end tell
   end mWordImportPrefs

Note: Notice that the import preferences are set for the application not the open document. This handler would be better used with a script that creates the document from a template after the preferences have been set.

Step 5 Now that we have a file to import and a document to place it in, we will check for a selection. If there is a text frame or insertion point selection, it will be used for placing the file. Otherwise the file will be placed on the first page of the document. The call to this handler will go directly after the call to mWordImportPrefs()

--the call to placeFile
   placeFile(docRef, fileRef)
--the handler
   (*Uses text frame or insertion point if selected, otherwise the page imports the file*)
   on placeFile(docRef, fileRef)
      tell application "Adobe InDesign CC 2015"
	  set selList to selection
	  if selection is {} then
	      set pageRef to page 1 of docRef
	      tell margin preferences of pageRef
		  set x to left
		  set y to top
	      end tell
	      tell pageRef
		  place fileRef place point [x, y]
	      end tell
	   else if class of item 1 of selList is in {insertion point, text frame} then
	      tell item 1 of selList
		  place fileRef
	      end tell
	   end if
	end tell
   end placeFile

Step 6 Optional

At this point you might want to decide this is all you want your script to do. Or you could have the user decide on the options as part of a custom dialog. The reason for these options is that bullet and numbered text comes in from Microsoft Word as styled with the Normal paragraph style with bullet and numbering overrides. There are several reasons that you might want to use these options:

  • You will be removing overrides on the Normal paragraph style where it is used for body text.
  • Styling for the Numbering style needs to be different than the Normal style.

If you use the following options, make sure the paragraph styles for the document include one named Bullet and one named Numbering. For the purpose of the demonstration script we have set two variables at the top of the script to determine the option choices:

   set changeBullets to true
   set changeNumbering to false

Then after the call to placeFile in the top portion of the script, we add the following calls.

   if changeBullets then
      changeToBulletStyle()
   end if
   if changeNumbering then
      changeToNumberStyle()
   end if

Here is the handler for changeToBulletStyle().

   (*Changes Normal text with Bullet override to Bullet paragraph style*)
    on changeToBulletStyle()
	tell application "Adobe InDesign CC 2015"
	   set find text preferences to nothing
	   set change text preferences to nothing
	   set docRef to document 1
	   set findAttrib to {applied paragraph style:"Normal", bullets and numbering list type:bullet list}
           set properties of find text preferences to findAttrib
	   tell docRef
		set changeAttrib to paragraph style "Bullet"
		set foundSet to find text
	   end tell
	   if foundSet is not {} then
		set applied paragraph style of change text preferences to changeAttrib
	   end if
	   tell docRef
		set changedText to change text
	   end tell
	   set find text preferences to nothing
	   set change text preferences to nothing
	end tell
   end changeToBulletStyle

We will leave the handler for changeToNumberStyle() up to the reader. The code for the handler will be almost exactly the same as that for ChangeToBulletStyle, so it should not be that much of a challenge. The one line you may need help with is the one that sets the findAttrib.

   set findAttrib to {applied paragraph style:"Normal", bullets and numbering list type:numbered list}

And, don’t forget to change the name of the paragraph style to Numbering.

ONWARD AND UPWARD

Yes, there is a fair amount of code involved with this script. The controlling factor for a successful Microsoft Word import is to have the import preferences set properly. Once these preferences are set, you may find your documents import fairly satisfactory even without the script. But there may still be a fair amount of hand massaging left to do. The big challenge is to get the person creating the file to use paragraph styles to style their text.