### 15.8 Including RTF code for Word output

If you want to do complicated things with RTF, you need to know the coding rules. Microsoft provides very little in the way of documentation, and the specification is incomplete. The best approach is to do what you want in a tiny file in Word itself, save as RTF, and use the Omni Systems pretty-print utility to make the result readable:

    pprtf myfile.rtf > myfile.txt

Study what Word did to produce that output. Make sure the braces {} are balanced in the fragment you extract from the Word output, and double the backslashes.

For example, suppose you want to use a DITA2Go macro to pull an image into the title page for your Word document, so in RTF you get an INCLUDEPICTURE field:

    { INCLUDEPICTURE "MyLogo.bmp" \* MERGEFORMAT \d \x \y }

Because backslash is meaningful both in RTF code and in DITA2Go macros, you must double any backslashes within fields and then double them again for the macro; so you end up with something like this to get what you want into RTF:

    {\\field {\\*\\fldinst INCLUDEPICTURE "MyLogo.bmp" \\\\d \\\\x \\\\y
     \\\\* MERGEFORMAT }{\\fldrslt }}

If you look at the resulting RTF with a text editor after you run the DITA2Go conversion, you should see:

    {\field {\*\fldinst INCLUDEPICTURE "MyLogo.bmp" \\d \\x \\y
     \\* MERGEFORMAT }{\fldrslt }}

Line breaks are acceptable in RTF code.

Previous Topic: 15.7.9 Updating fields in Word to show linked graphics

Next Topic: 15.9 Turning on revision tracking in Word

Parent Topic: 15. Converting to print RTF

Sibling Topics:

15.1 Setting up a print RTF project

15.2 Adjusting output for different versions of Word

15.3 Converting paragraph and character formats

15.4 Modifying text appearance

15.5 Converting cross references and hypertext links

15.6 Converting tables to print RTF

15.7 Managing graphics for print RTF

15.9 Turning on revision tracking in Word

15.10 Managing Word output after conversion

15.11 Converting to OpenOffice or StarOffice