Skip to main content
Trevor:
Legend
December 24, 2014
Question

Map Paragraph and Character Styles

  • December 24, 2014
  • 1 reply
  • 1872 views

Hello all,

I am trying to import Word documents based on the Word Import Preset documents.

Here's an example smp document

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<Sangam-Import-Preset reader-type="Word/RTF">

    <!--Style mappings take the form of key-value pairs consisting of:

style-name: Source document's style name, for example RTF style name.

This attribute is mandatory and the value cannot be an empty string.

mapped-to: Target InDesign document's style name.

This attribute is mandatory but can take an empty string as its value.-->

    <Style-Mappings>

        <Paragraph-Style-Mappings>

            <Mapping style-name="Body Text" mapped-to="Body 2" />

            <Mapping style-name="Heading 1" mapped-to="Heading 1" />

            <Mapping style-name="Normal" mapped-to="Normal 2" />

        </Paragraph-Style-Mappings>

        <Character-Style-Mappings>

            <Mapping style-name="Hyperlink" mapped-to="Hyp" />

        </Character-Style-Mappings>

    </Style-Mappings>

    <!--Each Import Preference has two mandatory attributes:

name: Name of the preference (cannot be an empty string).

value:Value of the preference (cannot be an empty string).

For boolean preferences, type 0 for false and 1 for true.-->

    <Import-Preferences>

        <Preference name="import-toc" value="1" />

        <Preference name="import-index" value="1" />

        <Preference name="import-hyperlink" value="1" />

        <Preference name="import-tables" value="1" />

        <Preference name="import-footnotes" value="1" />

        <Preference name="import-endnotes" value="1" />

        <Preference name="import-track-changes" value="1" />

        <Preference name="import-preserve-graphics" value="1" />

        <Preference name="spacing" value="1" />

        <Preference name="break-before-para" value="0" />

        <Preference name="use-typographers-quotes" value="1" />

        <Preference name="convert-tables-to" value="0" />

        <Preference name="remove-formatting" value="0" />

        <Preference name="dont-strip-char-formatting" value="0" />

        <Preference name="bring-unused-styles" value="0" />

        <Preference name="para-style-clash-option" value="0" />

        <Preference name="char-style-clash-option" value="0" />

        <Preference name="use-style-mappings" value="1" />

        <Preference name="convert-BN-to-text" value="0" />

    </Import-Preferences>

</Sangam-Import-Preset>

Everything should be easy to set in the WordRTFImportPreference except for the mappings.

I tried using app.activeDocument. paraStyleMappings.add("Normal","Normal 2",   MapType.STYLE_MAPPING_RULE) after setting app.generalPreferences.mapStylesOnContentPlace = true

Doesn't work . I suspect the mappings are only good for XML placements and not Word ones, in which case I guess the way to do it would be to us changeText() on the styles.  This is not a great solution as the changes would be done after placement unlike when using the UI before the placement.

Has anyone done this or got any ideas?

Regards,

Trevor

1 reply

Community Expert
May 30, 2018

Hi Trevor,

sorry for reviving this old thread, but:

Did you find a solution to load a particular smp document to app.wordRTFImportPreferences ?

Available files are stored in:

~/AppData/Roaming/Adobe/InDesign/Version%2013.0/de_DE/Word-Importvorgaben/

for my German InDesign CC 2018.1 on Windows 10.

I bolded the variable parts of the path. They depend on version and localization.

Regards,
Uwe

Trevor:
Trevor:Author
Legend
June 1, 2018

Sorry Uwe, I won't be able to look into this until Sunday.

Trevor:
Trevor:Author
Legend
June 5, 2018

Hi Uwe,

I didn't have any chance to try out anything but the way that one could possibly go is to use duplicate the word document and then using the smp map rename the style names in the duplicate file using vbs / powshell / applescript or some npm package

There might be a npm the you can call strait from ExtendScript, you'll have to check. I have used one for Excel that is very good for reading and writing / changing xlxs files from ExtendScript there might well be one that does the same for docs files but the vbs / applescript is probably very simple even without any experience in it as long as you have access to a site like Google.

Once the Word files been manipulated you can just import it as is and it will "be mapped"

Regards

Trevor


I did a quick search for renaming Word styles renaming Word styles with VBA - Stack Overflow

ActiveDocument.Styles(3).NameLocal = "abbracadabra"

You could build up a script dynamically and then call a doScript.

If multiple Word styles are mapped to the same InDesign style then one could have the script change the applied Word style to to the relevant style.

The problem with this method is that the client needs to have Word installed it could well be that one of the npm packages doesn't require Word and would also work quicker as it would work on the file contents without processing the "live / open" document.