# C1.C1Pdf.C1PdfDocument.DrawStringRtf

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_" data-uid="C1.C1Pdf.C1PdfDocument.DrawStringRtf*">DrawStringRtf Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_" data-uid="C1.C1Pdf.C1PdfDocument.DrawStringRtf*"></a>
<h4 id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_System_String_System_Drawing_Font_System_Drawing_Brush_System_Drawing_RectangleF_" data-uid="C1.C1Pdf.C1PdfDocument.DrawStringRtf(System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.RectangleF)">DrawStringRtf(string, Font, Brush, RectangleF)</h4>
<div class="markdown level1 summary"><p>Draws an RTF string in the specified rectangle with the specified <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.brush">Brush</a> and <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.font">Font</a> objects.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public int DrawStringRtf(string text, Font font, Brush brush, RectangleF rc)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function DrawStringRtf(text As String, font As Font, brush As Brush, rc As RectangleF) As Integer</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">text</span></td>
      <td><p>RTF string to draw.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.font">Font</a></td>
      <td><span class="parametername">font</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.font">Font</a> object that defines the appearance and size of the drawn text.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.brush">Brush</a></td>
      <td><span class="parametername">brush</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.brush">Brush</a> object that defines the color of the drawn text.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.rectanglef">RectangleF</a></td>
      <td><span class="parametername">rc</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.rectanglef">RectangleF</a> structure that specifies the location of the drawn text, in points from the top left
corner of the page.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><p>The index of first character that was not printed because it did not fit in the specified rectangle, or the value of
<see>int.MaxValue</see> if the entire string was rendered.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_System_String_System_Drawing_Font_System_Drawing_Brush_System_Drawing_RectangleF__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method is similar to <a class="xref" href="C1.C1Pdf.C1PdfDocument.MeasureString.html#C1_C1Pdf_C1PdfDocument_MeasureString_System_String_System_Drawing_Font_System_Single_">MeasureString(string, Font, float)</a>, except it recognizes Rtf (Rich Text Format) 
strings like those used in the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.forms.richtextbox">RichTextBox</a> control.</p>
<p>There are two types of RTF strings:</p>
<p>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 <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.forms.richtextbox">RichTextBox</a> control
using the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.forms.richtextbox.rtf">Rtf</a> property, or from Rtf files saved to disk.
In this case, the <code class="paramref">font</code> and <code class="paramref">brush</code> parameters are not used.</p>
<p>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 <code class="paramref">font</code> and <code class="paramref">brush</code> parameters are used
to build the Rtf header automatically.</p>
<p>The <b>DrawStringRtf</b> 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. To do this, use the overload that
takes the starting character in the text as a parameter.</p>
</div>


<a id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_" data-uid="C1.C1Pdf.C1PdfDocument.DrawStringRtf*"></a>
<h4 id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_System_String_System_Drawing_Font_System_Drawing_Brush_System_Drawing_RectangleF_System_Int32_" data-uid="C1.C1Pdf.C1PdfDocument.DrawStringRtf(System.String,System.Drawing.Font,System.Drawing.Brush,System.Drawing.RectangleF,System.Int32)">DrawStringRtf(string, Font, Brush, RectangleF, int)</h4>
<div class="markdown level1 summary"><p>Draws an RTF string in the specified rectangle with the specified <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.brush">Brush</a> and <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.font">Font</a> objects,
starting at a given offset within the string.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public int DrawStringRtf(string text, Font font, Brush brush, RectangleF rc, int firstChar)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function DrawStringRtf(text As String, font As Font, brush As Brush, rc As RectangleF, firstChar As Integer) As Integer</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">text</span></td>
      <td><p>RTF string to draw.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.font">Font</a></td>
      <td><span class="parametername">font</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.font">Font</a> object that defines the appearance and size of the drawn text.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.brush">Brush</a></td>
      <td><span class="parametername">brush</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.brush">Brush</a> object that defines the color of the drawn text.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.rectanglef">RectangleF</a></td>
      <td><span class="parametername">rc</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.drawing.rectanglef">RectangleF</a> structure that specifies the location of the drawn text, in points from the top left corner of the page.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">firstChar</span></td>
      <td><p>Index of the first character to draw (usually the return value of a previous call to <b>DrawStringRtf</b>).</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><p>The index of first character that was not printed because it did not fit in the specified rectangle, or the value of
<see>int.MaxValue</see> if the entire string was rendered.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_System_String_System_Drawing_Font_System_Drawing_Brush_System_Drawing_RectangleF_System_Int32__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method is similar to <a class="xref" href="C1.C1Pdf.C1PdfDocument.MeasureString.html#C1_C1Pdf_C1PdfDocument_MeasureString_System_String_System_Drawing_Font_System_Single_">MeasureString(string, Font, float)</a>, except it recognizes Rtf (Rich Text Format) 
strings like those used in the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.forms.richtextbox">RichTextBox</a> control.</p>
<p>There are two types of RTF strings:</p>
<p>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 <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.forms.richtextbox">RichTextBox</a> control
using the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.forms.richtextbox.rtf">Rtf</a> property, or from Rtf files saved to disk.
In this case, the <code class="paramref">font</code> and <code class="paramref">brush</code> parameters are not used.</p>
<p>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 <code class="paramref">font</code> and <code class="paramref">brush</code> parameters are used
to build the Rtf header automatically.</p>
<p>The <b>DrawStringRtf</b> 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.</p>
</div>
<h5 id="C1_C1Pdf_C1PdfDocument_DrawStringRtf_System_String_System_Drawing_Font_System_Drawing_Brush_System_Drawing_RectangleF_System_Int32__examples">Examples</h5>
<p>The code below renders a long string into several pages, using the return value
from the <a class="xref" href="C1.C1Pdf.C1PdfDocument.DrawString.html#C1_C1Pdf_C1PdfDocument_DrawString_System_String_System_Drawing_Font_System_Drawing_Brush_System_Drawing_RectangleF_System_Drawing_StringFormat_">DrawString(string, Font, Brush, RectangleF, StringFormat)</a> method to determine where to continue printing.</p>
<pre><code class="lang-csharp">// 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 &lt; int.MaxValue; )
{
    if (start &gt; 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);</code></pre>

</div>
