Word and RTF files

S

spiritualfields

Using Notepad, I typed the following, using the book The Developer's Guide To
WINHELP.EXE as a reference, and saved it as HEADER.RTF (it's approx 30 lines,
and you can probably skip over it to get to the rest of my problem
description, which is where Word 2003 gets involved):

{\rtf1

{\fonttbl
{\f0\fswiss MS Sans Serif;}
{\f1\fmodern Courier;}
{\f2\ftech Symbol;}
{f3\froman Times New Roman;}
{f4\fnil\ System;}
}

{\comment
Color table follows. Colors are:
1 - Black
2 - Blue
3 - Cyan
4 - Green
5 - Magenta
6 - Red
7 - Yellow
8 - White
9 - Dark Blue
10 - Dark Cyan
11 - Dark Green
12 - Dark Magenta
13 - Dark Red
14 - Dark Yellow
15 - Dark Gray
16 - Light Gray
}

{\colortbl;
\red0\green0\blue0;
\red0\green0\blue255;
\red0\green255\blue255;
\red0\green255\blue0;
\red255\green0\blue255;
\red255\green0\blue0;
\red255\green255\blue;
\red255\green255\blue255;
\red0\green0\blue127;
\red0\green127\blue127;
\red0\green127\blue0;
\red127\green0\blue127;
\red127\green0\blue0;
\red127\green127\blue0;
\red127\green127\blue127;
\red192\green192\blue192;
}

\ansi\deff0\pard
}

After saving this file, I opened it using Word 2003, but none of the text
showed. I just get a blank screen, yet the Caption Bar at the top of Word
indicates that my file HEADER.RTF is indeed open and being viewed.

On my system, I have Notepad, TextPad, Wordpad, and Word 2003 as my word
processors. The file opens and displays properly when I open it with Notepad
and Textpad. However, when I open it with Wordpad, only the characters
enclosed with the \comment brace are displayed. And as I mentioned earlier,
Word displays none of the content whatsover.

What I then did was copy the entire contents of the HEADER.RTF file and
pasted it into a new Word document, saving it as HEADER1.RTF. The first thing
I noticed is that this new file is 5kb long, while the original was only 1kb.

However, now notepad and wordpad, when viewing this new file, show the
original text but also interspersed before and within it are a host of
different formatting characters.

I have no idea what is going on here, and why I can't just type an RTF
document and have all of my word processors read it properly, the way I typed
it.

To reproduce what I'm talking about, all you have to do is copy the contents
of the file that I pasted, and save it into a notepad file as an RTF file
(not .txt). And then try to open it in Word.

Ultimately, I'll probably use Word to write my RTF files. But what is
upsetting right now is why it won't acknowledge an RTF file written with
Notepad.
 
J

Jezebel

Perhaps it would help if you read the RTF file format specification. The
sample you posted has no displayable content. Look at what it actually
contains: 1) the font table, 2) a comment, which the rendering application
is expected to ignore, 3) the color table, and 4) a paragraph style
specification.

Word is rendering it entirely correctly: *there is nothing to display*.
 
S

spiritualfields

This is a new paradigm for me. With word processors, I'm used to seeing text
show up as text, whether they are commands, macros, comments, etc. So writing
text to a file in notepad that doesn't display in Word is a little strange.
So, if I'm ever working with a notepad RTF file, and I want to look at it in
Word, then I need to paste the contents of the notepad file into a Word
document and create it as a Word RTF file in order to see all the content?
That is what I had to do in this case. I'm still not entirely sure what is
going on, whether this is an RTF thing or a Word thing. As I said, notepad
and textpad had no problem viewing the original HEADER.RTF file when it was
created as a notepad file. Any more light you can shed on this will be
appreciated.
 
J

Jezebel

I think you have a conceptual block here. At the operating system level, a
RTF document is a text file. If you open it in Notepad you see whatever the
file happens to contain.

As a file *format*, RTF is a way to deliver formatted text ("Rich Text")
using plain text characters. In this sense it is similar to HTML. An RTF
file contains two types of information: the text itself, and formatting
instructions to specify how that text should be rendered (ie size, colour,
typeface, etc). If you open the file in Notepad, you're seeing all the
instructions; if you open the same file in Word, you're seeing the *result*
of those instructions. And in the case of your example, since there's no
actual content, the result is a blank page.

By analogy, try opening an HTML file in Notepad, and compare what you see
with the same page opened in a browser.

See here for more info: http://en.wikipedia.org/wiki/Rich_Text_Format
 
S

spiritualfields

"By analogy, try opening an HTML file in Notepad, and compare what you see
with the same page opened in a browser."

Yes, that makes sense. My only lingering question now is: after I pasted the
cotents of the HEADER.RTF file into a Word document and saved it as
HEADER1.RTF, Word displayed the formatting code thereafter, whenever I opened
that Word created file, just as if the formatting code was normal text. I'm
not quite getting that.

Thanks for that link.
 
J

Jezebel

Yes, that makes sense. My only lingering question now is: after I pasted
the
cotents of the HEADER.RTF file into a Word document and saved it as
HEADER1.RTF, Word displayed the formatting code thereafter, whenever I
opened
that Word created file, just as if the formatting code was normal text.
I'm
not quite getting that.

In this case, the RTF material you pasted *IS* normal text, embedded within
an RTF document.
 
S

spiritualfields

In this case, the RTF material you pasted *IS* normal text, embedded within
an RTF document.

Embedded in such a way that it is visible ;) I think I'm going to let all of
this sink in. I plan on using Word to write my rtf files anyway, so I'll be
able to see the formatting code when I open the file.

Thanks for all the information.
 
J

Jezebel

I think you're still missing the point a little. If you can *see* the
formatting code (in Word), then it's not an RTF file. It's simply RTF
content within a document. You can of course use Word simply as a text
editor: enter your RTF code into the document, save it *as text*, then
change the file extension from .txt to .rtf. (Note that this doesn't work in
reverse: if the initial characters of a text-formatted file are "{\rtf" then
Word will interpret it as rtf anyway, regardless of the file extension.)
 
G

Graham Mayor

If you need to hand code the RTF for some reason, instead of letting Word do
the formatting, and creation of the RTF code, you will probably want to use
Word as a plain text editor. If you save as RTF from Word you will have two
sets of information included - try viewing such a file again in Notepad or
set tools > options > general > confirm conversions on open then open RTF
documents as plain text. Edit and save again as plain text.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

spiritualfields

Jezebel said:
change the file extension from .txt to .rtf. (Note that this doesn't work in
reverse: if the initial characters of a text-formatted file are "{\rtf" then
Word will interpret it as rtf anyway, regardless of the file extension.)

Yes, this is what I found initially confusing. I think I'm beginning to
understand this a little better.
 
S

spiritualfields

Graham Mayor said:
If you need to hand code the RTF for some reason, instead of letting Word do
the formatting, and creation of the RTF code, you will probably want to use
Word as a plain text editor. If you save as RTF from Word you will have two
sets of information included - try viewing such a file again in Notepad or
set tools > options > general > confirm conversions on open then open RTF
documents as plain text. Edit and save again as plain text.

I'm working from a book titled "The Developer's Guide To WINHELP.EXE", by
Jim Mischel. It was published in 1994, but from what I understand, most of
the formatting code and macros are still good. I expect to encounter all
sorts of compatiblity problems between the way Windows XP does things versus
the Windows 3.1 way. One area is in the way the program groups and program
items used to be created in the directory. Windows 3.1 relied on a PIF
editor, and I have no idea what the Window's XP counterpart to this is
(though I'm hoping that I can effectively accomplish the same thing by
putting shortcuts to the help compilers in my practice help folder). From
what I can tell so far, the Windows 3.1 Program Items were icons that were
inserted in various directories (using the PIF editor), from which those
progams could be run by clicking on the icon, even though the actual
executables were located in a different directory.

The book started out with that HEADER.RTF file, using Notepad as the editor.
On my own I then opened Word up to the file to see what appeared, and seeing
a blank page confused me. With yours and Jezebel's help, I'm beginning to get
a clearer picture. I had intended to use Word as my word processor while I
learn about Windows Help, but I'll rethink that. My ultimate goal is not to
write a specific help file for a specific application, but to write a help
authoring tool, because I'm tired of always relying on someone else's. I'm
thinking that the best way to approach this task is to do as much hand coding
of the help files as possible. Ultimately, when I write the app, I'll be
using the Win32 RichTextEdit control as the editor, wrapped by an MFC
CRichTextEdit class object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top