DrawString provides all the functionality you need for rendering paragraphs using a single font and color.
If you want to render paragraphs with rich format, mixing fonts and colors, you should use the DrawStringRtf method instead. DrawStringRtf is similar to DrawString, except the string is interpreted as RTF.
For example, the code below renders a line of text with some bold and italic characters in it:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim font As New Font("Arial", 12) Dim rect As RectangleF = pdf.PageRectangle rect.Inflate(- 72, - 72) Dim s As String s = "To {\b boldly} go where {\i no one} has gone before!" pdf.DrawStringRtf(s, font, Brushes.Black, rect) |
To write code in C#
C# |
Copy Code
|
---|---|
Font font = new Font("Arial", 12); RectangleF rect = pdf.PageRectangle; rect.Inflate(-72, -72); pdf.DrawStringRtf(@"To {\b boldly} go where {\i no one} has gone before!", font, Brushes.Black, rect); |
Notice that the string does not contain a full RTF document. It has no \rtf1 header, font or color tables. The DrawStringRtf method recognizes that and builds the necessary RTF header automatically, based on the Font and Brush parameters provided.
If the string contained a complete RTF header, that would be used in lieu of the font and brush parameters specified in the call DrawStringRtf. This would be the case if the string were copied from a RichTextBox control or loaded from an RTF file.