# C1.Xaml.Pdf.C1PdfDocument.DrawElement

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_" data-uid="C1.Xaml.Pdf.C1PdfDocument.DrawElement*">DrawElement Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_" data-uid="C1.Xaml.Pdf.C1PdfDocument.DrawElement*"></a>
<h4 id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_System_Windows_FrameworkElement_System_Windows_Rect_C1_Util_ContentAlignment_System_Windows_Media_Stretch_" data-uid="C1.Xaml.Pdf.C1PdfDocument.DrawElement(System.Windows.FrameworkElement,System.Windows.Rect,C1.Util.ContentAlignment,System.Windows.Media.Stretch)">DrawElement(FrameworkElement, Rect, ContentAlignment, Stretch)</h4>
<div class="markdown level1 summary"><p>Draws the specified <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.media.imaging.writeablebitmap">WriteableBitmap</a> object at the specified location,
adjusting the image size as specified by the <code class="paramref">align</code> and
<code class="paramref">stretch</code> parameters.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void DrawElement(FrameworkElement e, Rect rc, ContentAlignment align, Stretch stretch)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub DrawElement(e As FrameworkElement, rc As Rect, align As ContentAlignment, stretch As Stretch)</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.windows.frameworkelement">FrameworkElement</a></td>
      <td><span class="parametername">e</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> to render into the document.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">Rect</span></td>
      <td><span class="parametername">rc</span></td>
      <td><p><span class="xref">System.Windows.Rect</span> structure that specifies the location of the drawn element, in points from the top left corner of the page.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">ContentAlignment</span></td>
      <td><span class="parametername">align</span></td>
      <td><p><span class="xref">C1.Util.ContentAlignment</span> value that specifies how the element should be aligned within the rectangle.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.media.stretch">Stretch</a></td>
      <td><span class="parametername">stretch</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.media.stretch">Stretch</a> value that specifies how the element should be sized to fit the rectangle.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_System_Windows_FrameworkElement_System_Windows_Rect_C1_Util_ContentAlignment_System_Windows_Media_Stretch__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method must be called from the main thread. Calling it from a background thread will
raise a cross-thread exception when the method tries to access the properties of the
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> being rendered.</p>
</div>


<a id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_" data-uid="C1.Xaml.Pdf.C1PdfDocument.DrawElement*"></a>
<h4 id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_System_Windows_FrameworkElement_System_Windows_Rect_System_Windows_Rect_" data-uid="C1.Xaml.Pdf.C1PdfDocument.DrawElement(System.Windows.FrameworkElement,System.Windows.Rect,System.Windows.Rect)">DrawElement(FrameworkElement, Rect, Rect)</h4>
<div class="markdown level1 summary"><p>Draws a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> into the document at a specified position.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void DrawElement(FrameworkElement e, Rect rc, Rect rcClip)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub DrawElement(e As FrameworkElement, rc As Rect, rcClip As Rect)</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.windows.frameworkelement">FrameworkElement</a></td>
      <td><span class="parametername">e</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> to render into the document.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">Rect</span></td>
      <td><span class="parametername">rc</span></td>
      <td><p><span class="xref">System.Windows.Rect</span> where the element will be rendered.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">Rect</span></td>
      <td><span class="parametername">rcClip</span></td>
      <td><p><span class="xref">System.Windows.Rect</span> that defines the clipping bounds.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_System_Windows_FrameworkElement_System_Windows_Rect_System_Windows_Rect__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method uses a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.media.visualtreehelper">VisualTreeHelper</a> to render each of the 
primitives that compose the root element. It does not convert the element
into a bitmap. As a result, the output is smaller and resolution independent;
however, the result is not as faithful as a bitmap rendering. To render an
element as a bitmaps, create a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.media.imaging.writeablebitmap">WriteableBitmap</a> and pass it to the
<a class="xref" href="C1.Xaml.Pdf.C1PdfDocument.DrawImage.html#C1_Xaml_Pdf_C1PdfDocument_DrawImage_System_Windows_Media_Imaging_WriteableBitmap_System_Windows_Rect_">DrawImage(WriteableBitmap, Rect)</a> method.</p>
<p>This method must be called from the main thread. Calling it from a background thread will
raise a cross-thread exception when the method tries to access the properties of the
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> being rendered.</p>
</div>


<a id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_" data-uid="C1.Xaml.Pdf.C1PdfDocument.DrawElement*"></a>
<h4 id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_System_Windows_FrameworkElement_System_Windows_Rect_" data-uid="C1.Xaml.Pdf.C1PdfDocument.DrawElement(System.Windows.FrameworkElement,System.Windows.Rect)">DrawElement(FrameworkElement, Rect)</h4>
<div class="markdown level1 summary"><p>Draws a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> into the document at a specified position.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void DrawElement(FrameworkElement e, Rect rc)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub DrawElement(e As FrameworkElement, rc As Rect)</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.windows.frameworkelement">FrameworkElement</a></td>
      <td><span class="parametername">e</span></td>
      <td><p><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> to render into the document.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">Rect</span></td>
      <td><span class="parametername">rc</span></td>
      <td><p><span class="xref">System.Windows.Rect</span> where the element will be rendered.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Xaml_Pdf_C1PdfDocument_DrawElement_System_Windows_FrameworkElement_System_Windows_Rect__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method uses a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.media.visualtreehelper">VisualTreeHelper</a> to render each of the 
primitives that compose the root element. It does not convert the element
into a bitmap. As a result, the output is smaller and resolution independent;
however, the result is not as faithful as a bitmap rendering. To render an
element as a bitmaps, create a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.media.imaging.writeablebitmap">WriteableBitmap</a> and pass it to the
<a class="xref" href="C1.Xaml.Pdf.C1PdfDocument.DrawImage.html#C1_Xaml_Pdf_C1PdfDocument_DrawImage_System_Windows_Media_Imaging_WriteableBitmap_System_Windows_Rect_">DrawImage(WriteableBitmap, Rect)</a> method.</p>
<p>This method must be called from the main thread. Calling it from a background thread will
raise a cross-thread exception when the method tries to access the properties of the
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> being rendered.</p>
</div>
</div>
