ComponentOne PDF for .NET
C1.C1Pdf Namespace / C1PdfDocument Class / DrawStringRtf Method / DrawStringRtf(String,Font,Brush,RectangleF,Int32) Method
RTF string to draw.
System.Drawing.Font object that defines the appearance and size of the drawn text.
System.Drawing.Brush object that defines the color of the drawn text.
System.Drawing.RectangleF structure that specifies the location of the drawn text, in points from the top left corner of the page.
Index of the first character to draw (usually the return value of a previous call to DrawStringRtf).
Example

In This Topic
    DrawStringRtf(String,Font,Brush,RectangleF,Int32) Method
    In This Topic
    Draws an RTF string in the specified rectangle with the specified System.Drawing.Brush and System.Drawing.Font objects, starting at a given offset within the string.
    Syntax
    'Declaration
     
    
    Public Overloads Function DrawStringRtf( _
       ByVal text As String, _
       ByVal font As Font, _
       ByVal brush As Brush, _
       ByVal rc As RectangleF, _
       ByVal firstChar As Integer _
    ) As Integer
    public int DrawStringRtf( 
       string text,
       Font font,
       Brush brush,
       RectangleF rc,
       int firstChar
    )

    Parameters

    text
    RTF string to draw.
    font
    System.Drawing.Font object that defines the appearance and size of the drawn text.
    brush
    System.Drawing.Brush object that defines the color of the drawn text.
    rc
    System.Drawing.RectangleF structure that specifies the location of the drawn text, in points from the top left corner of the page.
    firstChar
    Index of the first character to draw (usually the return value of a previous call to DrawStringRtf).

    Return Value

    The index of first character that was not printed because it did not fit in the specified rectangle, or the value of int.MaxValue if the entire string was rendered.
    Remarks

    This method is similar to MeasureString(String,Font,Single), except it recognizes Rtf (Rich Text Format) strings like those used in the System.Windows.Forms.RichTextBox control.

    There are two types of RTF strings:

    1) Complete RTF strings contain an Rtf header that specifies the fonts and colors used within the string. These strings can be obtained from a System.Windows.Forms.RichTextBox control using the System.Windows.Forms.RichTextBox.Rtf property, or from Rtf files saved to disk. In this case, the font and brush parameters are not used.

    2) Partial RTF strings contain embedded Rtf tags but no Rtf header. These strings are easy to build in code and can be used to render text with special attributes such as bold and italics (for example: "this text contains {\b BOLD} and {\i ITALICS}". In this case, the font and brush parameters are used to build the Rtf header automatically.

    The DrawStringRtf method returns the index of the first character that was not printed because it did not fit the output rectangle. You can use this value to make text flow from page to page, or from one frame to another within a page. Note that this value is not an index into the raw Rtf input, but into the text represented by the Rtf. See example below.

    Example
    The code below renders a long string into several pages, using the return value from the DrawString(String,Font,Brush,RectangleF,StringFormat) method to determine where to continue printing.
    // calculate page rectangle
    RectangleF rcPage = _c1pdf.PageRectangle;
    rcPage.Inflate(-72, -72);
                
    // get Rtf to render
    string text = richTextBox1.Rtf;
                
    // print the RTF string spanning multiple pages
    _c1pdf.Clear();
    for (int start = 0; start < int.MaxValue; )
    {
        if (start > 0) _c1pdf.NewPage();
        start = _c1pdf.DrawStringRtf(text, Font, 
               Brushes.Black, rcPage, start);
    }
                
    // show the result
    string fn = @"c:\temp\test\rtf.pdf";
    _c1pdf.Save(fn);
    System.Diagnostics.Process.Start(fn);
    See Also