diff --git a/knowledge-base/qrcode-barcode-chart-export-to-image.md b/knowledge-base/qrcode-barcode-chart-export-to-image.md index 27cdc19e9..7ae449d23 100644 --- a/knowledge-base/qrcode-barcode-chart-export-to-image.md +++ b/knowledge-base/qrcode-barcode-chart-export-to-image.md @@ -1,11 +1,11 @@ --- -title: Export QRCode, Barcode, or Chart to Image -description: Learn how to convert and export a Telerik Blazor QRCode, Barcode, or Chart to an image and send it to the .NET runtime. +title: Export QRCode, Barcode, Chart or Diagram to Image +description: Learn how to convert and export a Telerik Blazor QRCode, Barcode, Chart, or Diagram to an image and send it to the .NET runtime. type: how-to -page_title: How to Export Telerik QRCode, Barcode, or Chart to Image +page_title: How to Export Telerik QRCode, Barcode, Chart, or Diagram to Image slug: qrcode-barcode-chart-kb-export-to-image -tags: telerik, blazor, qrcode, barcode, chart -ticketid: 1572189, 1588186, 1667798 +tags: telerik, blazor, qrcode, barcode, chart, diagram +ticketid: 1572189, 1588186, 1667798, 1697494, 1697884 res_type: kb --- @@ -32,6 +32,7 @@ This KB answers the following questions: * How to create an image from the Telerik QRCode for Blazor? * How to convert a Barcode, Chart, or QRCode from SVG to an image? * How to save a Barcode or QRCode as an image? +* How to export a Diagram to a PNG file? ## Solution @@ -48,7 +49,11 @@ When using the `SVG` rendering mode: > When using a Blazor app with **Server** render mode, make sure to [increase the SignalR max message size](slug:common-kb-increase-signalr-max-message-size), otherwise the Base64 data URI may not reach the .NET runtime. ->caption Export QRCode, BarCode, or Chart to Image +> The following examples demonstrates JavaScript APIs, which are not subject to Telerik technical support. + +### Export BarCode, Chart and QRCode + +>caption Export QRCode, BarCode, or Chart to PNG Image ````RAZOR @inject IJSRuntime js @@ -65,7 +70,7 @@ When using the `SVG` rendering mode: Export to PNG + OnClick="@OnExportButtonClick">Export to PNG
@@ -186,8 +191,6 @@ When using the `SVG` rendering mode: @code { - #nullable enable - private RenderingMode RenderingMode { get; set; } = RenderingMode.SVG; private string QrImageDataUrl { get; set; } = string.Empty; @@ -196,7 +199,7 @@ When using the `SVG` rendering mode: private List SeriesData1 { get; set; } = new(); private List SeriesData2 { get; set; } = new(); - private async Task OnQrCodeExportButtonClick() + private async Task OnExportButtonClick() { string jsFunctionName = RenderingMode == RenderingMode.SVG ? "getImageFromSvg" : "getImageFromCanvas"; @@ -254,10 +257,133 @@ When using the `SVG` rendering mode: } ```` -> The example in this KB article demonstrates JavaScript APIs, which are not subject to Telerik technical support. +### Export Diagram + +The required approach with a Telerik Blazor Diagram is the same as described above, with one exception. The `getBlobImage` JavaScript function must receive the exact Diagram width and height, instead of `svgBox.width` and `svgBox.height`. This is because the Diagram supports panning and the `svgBox` is larger than the visible component dimensions. Using `svgBox.width` and `svgBox.height` may result in a clipped PNG image. + +>caption Export Diagram to PNG Image + +````RAZOR +@inject IJSRuntime js + +Export Diagram to PNG + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@if (!string.IsNullOrEmpty(DiagramImageDataUrl)) +{ +

Diagram PNG

+ PNG from Diagram +} + +@* Move JavaScript code to a separate JS file *@ + + +@code { + private string DiagramImageDataUrl { get; set; } = string.Empty; + + private const int DiagramWidth = 480; + private const int DiagramHeight = 400; + + private async Task OnDiagramExportButtonClick() + { + string jsFunctionName = "getDiagramFromSvg"; + + DiagramImageDataUrl = await js.InvokeAsync(jsFunctionName, ".exportable-diagram", DiagramWidth, DiagramHeight); + } +} +```` ## See Also * [Barcode Overview](slug:barcode-overview) * [Chart Overview](slug:components/chart/overview) +* [Diagram Overview](slug:diagram-overview) * [QRCore Overview](slug:qrcode-overview)