# Html2Canvas

Namespace: **Wisej.Web.Ext.Html2Canvas**

Assembly: **Wisej.Web.Ext.Html2Canvas** (2.0.0.0)

* [Component](https://docs.wisej.com/api/wisej.base/general/wisej.base.component.md)
  * [Component](https://docs.wisej.com/api/wisej.web/general/wisej.web.component.md)
    * [Html2Canvas](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvas)

Implementation of the html2canvas (<https://html2canvas.hertzen.com/>) library. It's a singleton instance that can take a screenshot of a specific control or the entire browser and send the image back to the server.

{% tabs %}
{% tab title="C#" %}

```csharp
public class Html2Canvas : Component
```

{% endtab %}

{% tab title="VB.NET" %}

```php
Public Class Html2Canvas
    Inherits Component
```

{% endtab %}
{% endtabs %}

Usage is quite easy:

```csharp
  Html2Canvas.Screenshot(this, (image) => {
  image.Save(@"\images\screen.png");
});

  // or using asynchronous code:

  var image = await Html2Canvas.Screenshot(this.panel1);
  image.Save(@"\images\screen.png");
```

## Methods

### ![](https://2248866391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFp7MR1wemvcC5891_r%2F-MirBc8UH2o1iZfh0jrC%2F-MirBsnox1cbEBcVJYTK%2Fstatic.png?alt=media\&token=9c92a67d-a608-4268-bb67-eaee38f9c0e2)Screenshot(callback)

Takes a screenshot of the browser.

| Parameter    | Type                                                                                      | Description                                                                                                                               |
| ------------ | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| **callback** | [Action](https://docs.microsoft.com/en-us/dotnet/api/system.action?view=netframework-4.8) | Callback method that receives the [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) object. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception?view=netframework-4.8)

  If any of the arguments is null.

### ![](https://2248866391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFp7MR1wemvcC5891_r%2F-MirBc8UH2o1iZfh0jrC%2F-MirBsnox1cbEBcVJYTK%2Fstatic.png?alt=media\&token=9c92a67d-a608-4268-bb67-eaee38f9c0e2)Screenshot(options, callback)

Takes a screenshot of the browser.

| Parameter    | Type                                                                                                                            | Description                                                                                                                                                          |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **options**  | [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) | The [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) to pass to the html2canvas call. |
| **callback** | [Action](https://docs.microsoft.com/en-us/dotnet/api/system.action?view=netframework-4.8)                                       | Callback method that receives the [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) object.                            |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception?view=netframework-4.8)

  If any of the arguments is null.

### ![](https://2248866391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFp7MR1wemvcC5891_r%2F-MirBc8UH2o1iZfh0jrC%2F-MirBsnox1cbEBcVJYTK%2Fstatic.png?alt=media\&token=9c92a67d-a608-4268-bb67-eaee38f9c0e2)Screenshot(target, callback)

Takes a screenshot of the specified [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md).

| Parameter    | Type                                                                                      | Description                                                                                                                                                                                   |
| ------------ | ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **target**   | [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md)                 | The [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md) to render to an [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) |
| **callback** | [Action](https://docs.microsoft.com/en-us/dotnet/api/system.action?view=netframework-4.8) | Callback method that receives the [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) object.                                                     |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception?view=netframework-4.8)

  If any of the arguments is null.

### ![](https://2248866391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFp7MR1wemvcC5891_r%2F-MirBc8UH2o1iZfh0jrC%2F-MirBsnox1cbEBcVJYTK%2Fstatic.png?alt=media\&token=9c92a67d-a608-4268-bb67-eaee38f9c0e2)Screenshot(target, options, callback)

Takes a screenshot of the specified [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md).

| Parameter    | Type                                                                                                                            | Description                                                                                                                                                                                   |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **target**   | [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md)                                                       | The [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md) to render to an [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) |
| **options**  | [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) | The [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) to pass to the html2canvas call.                          |
| **callback** | [Action](https://docs.microsoft.com/en-us/dotnet/api/system.action?view=netframework-4.8)                                       | Callback method that receives the [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) object.                                                     |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception?view=netframework-4.8)

  If any of the arguments is null.

### ![](https://2248866391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFp7MR1wemvcC5891_r%2F-MirBc8UH2o1iZfh0jrC%2F-MirBsnox1cbEBcVJYTK%2Fstatic.png?alt=media\&token=9c92a67d-a608-4268-bb67-eaee38f9c0e2)ScreenshotAsync(options)

Asynchronously returns an [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) that represents a screenshot of the browser.

| Parameter   | Type                                                                                                                            | Description                                                                                                                                                          |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **options** | [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) | The [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) to pass to the html2canvas call. |

**Returns:** [Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=netframework-4.8). An awaitable [Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=netframework-4.8) that contains the screenshot.

### ![](https://2248866391-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFp7MR1wemvcC5891_r%2F-MirBc8UH2o1iZfh0jrC%2F-MirBsnox1cbEBcVJYTK%2Fstatic.png?alt=media\&token=9c92a67d-a608-4268-bb67-eaee38f9c0e2)ScreenshotAsync(target, options)

Asynchronously returns an [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) that represents a screenshot of the specified [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md) as it appears on the browser.

| Parameter   | Type                                                                                                                            | Description                                                                                                                                                                                   |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **target**  | [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md)                                                       | The [Control](https://docs.wisej.com/api/wisej.web/general/control/README.md) to render to an [Image](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image?view=netframework-4.8) |
| **options** | [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) | The [Html2CanvasOptions](https://docs.wisej.com/extensions/extensions/html2canvas/api/wisej.web.ext.html2canvas.html2canvasoptions) to pass to the html2canvas call.                          |

**Returns:** [Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=netframework-4.8). An awaitable [Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=netframework-4.8) that contains the screenshot.

## Inherited

### Methods

| Name                                                                                                                                                                    | Description | From                                                                             |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -------------------------------------------------------------------------------- |
| [Update()](https://github.com/iceteagroup/wisej-docs-extensions/tree/d4902cdfa9ee0ea2e5ec243650edd687a7d37a2f/extensions/html2canvas/api/wisej.web.component.md#update) |             | [Component](https://docs.wisej.com/api/wisej.web/general/wisej.web.component.md) |
