Printer Object
 
Syntax
 
Printer.TextRTF = strValue
 
Description
Renders RTF text on the page at the current cursor position.
 
RTF (Rich Text Format) allows you to embed special formatting codes into the text to be printed. You may obtain RTF text from many sources, including RTF files created by WordPad, Microsoft® Word, or from the Tradium Word Processor. Alternatively, you may choose to create the RTF text manually.
 
All RTF text starts with a header section that contains a font table and a color table (and possibly other optional elements). If you assign an RTF string without an RTF header to the TextRTF property, the Printer object will realize that the header is missing and will create one on the fly. This automatically generated header contains a single font and a single color (based on the control’s Font and TextColor properties.) Because there is a single font in the automatically generated header, you may change the font style and size, but not its name (typeface).
 
For example, the code below prints a string with embedded bold and italics:
 
Printer.TextRTF = "Hello. This is {\b BOLD}, and this is {\i ITALICS}." 
 
If you need to combine multiple typefaces into a single string, you must supply the RTF header yourself. The easiest way to do this is to create the document in WordPad, save it as RTF, then open the file in NotePad and tweak it.
 
For example, the code below prints a string with different fonts:
 
Printer.TextRTF = "{\rtf1\ansi\deff0\deftab720" & _
                  "{\fonttbl{\f0\fswiss Arial;}" & _
                  "{\f1\froman Courier New;}}" & _
                  "{\colortbl\red0\green0\blue0;}" & _
                  "\f0\fs22 Hello. This is Arial and " & _
                  "this is {\f1 Courier}." & _
                  "}"
 
You can also use RTF text in cell tables, headers, footers, text boxes, and regular paragraphs. To do this, enclose the text you want to print in curly braces ("{}").
 
The Printer object uses the Windows RichEdit component (RICHED20.DLL) to render RTF. RichEdit is powerful, but not as powerful as Microsoft® Word. In particular, RichEdit does not handle RTF tables, which means you cannot copy a table from Word and render it using the TextRTF property. The Printer object can, however, export tables into RTF files which can then be read into Word.
 
Note: RTF is an extremely powerful format, but it is also fairly time consuming to render. Use RTF only if you have to, because it will slow down the creation of your documents.
 
See Also
 
Example