Microsoft’s Interpretation of RTF landscape tags in Word

I have a rails application which generates RTF files based on site content. One of the data tables used in this report required that part of the report show in landscape mode in Microsoft Word.

There are a few documented RTF tags that should do this:

\landscape
\lndscpsxn
etc.

Word generally ignores both on their own, unless other some other elements in the RTF are perfect.

To start learning what Word actually requires to get landscape RTF pages within other pages, I created a basic RTF in word with two lines of text

“This is in a portrait page”
“This is in a landscape page”

Saved this in RTF format. 32k of junk!

After about an hour of pruning everything I could find that would not break the way the document appeared, I ended up with simply:

{\rtf1\ansi

{This is some text in portrait}

{\sect }

\pard \sectd \lndscpsxn\pgwsxn16840\pghsxn11901

{This is some text in landscape }

}

Voila!

Adjusted my app to manually force the following RTF tags in:

{\sect } \sectd \lndscpsxn\pgwsxn\pghsxn

prior to the page break and we were good!

This post is intended to save some googlers the 3 hours that I just wasted on it.

Leave a Reply