New to Telerik UI for BlazorStart a free 30-day trial

Diagram Export

Updated on May 18, 2026

The Telerik Diagram for Blazor allows you to export the current Diagram as a PNG image or a PDF document. The export methods return a base64-encoded data URL that you can use to download or further process the exported file.

Export Methods

To export the Diagram, capture a component reference and call one of the following methods:

MethodParametersReturn TypeDescription
ExportToPngAsyncnoneTask<string>Exports the Diagram as a PNG image and returns a base64-encoded data URL.
ExportToPdfAsyncPdfExportOptions?Task<string>Exports the Diagram as a PDF document and returns a base64-encoded data URL.

Both methods return a data URL string in the format data:<media-type>;base64,<data>. To get the raw bytes, strip the prefix up to and including the first comma.

PDF Export Options

Pass a PdfExportOptions object to ExportToPdfAsync to customize the PDF output. All properties are optional.

PropertyTypeDefaultDescription
AutoPrintbool?nullSpecifies if the Print dialog opens immediately after loading the document.
Authorstring?nullThe author metadata of the PDF document.
Creatorstring?nullThe creator metadata of the PDF document.
ImgDpiint?nullThe forced resolution of images, including SVGs, in the exported PDF. By default, images export at their native resolution.
Keywordsstring?nullThe keywords metadata of the PDF document.
Landscapebool?nullWhen true, the page uses landscape orientation. Defaults to portrait.
Marginstring?nullThe margins of the page. Supported units are mm, cm, in, and pt.
MultiPagebool?nullWhen true, exports child groups as separate pages.
PaperSizestring?nullThe paper size of the PDF document. Supported values are A0A10, B0B10, C0C10, Executive, Folio, Legal, Letter, and Tabloid.
Producerstring?nullThe producer metadata of the PDF document.
Subjectstring?nullThe subject metadata of the PDF document.
Titlestring?nullThe title metadata of the PDF document.

Example

The following example exports the Diagram as a PNG image or a PDF document and saves the file to disk.

Export the Diagram as PNG or PDF

@using Telerik.Blazor.Common.Export.Pdf

<TelerikButton OnClick="@OnExportPdfClick">Export as PDF</TelerikButton>
<TelerikButton OnClick="@OnExportPngClick">Export as PNG</TelerikButton>

<TelerikDiagram @ref="@DiagramRef" Height="420px" Zoom="0.8">
    <DiagramConnectionDefaults Type="@DiagramConnectionType.Cascading" />
    <DiagramLayout Type="@DiagramLayoutType.Tree" />
    <DiagramShapeDefaults Type="@DiagramShapeType.Rectangle" />

    <DiagramShapes>
        <DiagramShape Id="shape1">
            <DiagramShapeContent Text="Shape 1" />
        </DiagramShape>
        <DiagramShape Id="shape2">
            <DiagramShapeContent Text="Shape 2" />
        </DiagramShape>
        <DiagramShape Id="shape3">
            <DiagramShapeContent Text="Shape 3" />
        </DiagramShape>
        <DiagramShape Id="shape4">
            <DiagramShapeContent Text="Shape 4" />
        </DiagramShape>
        <DiagramShape Id="shape5">
            <DiagramShapeContent Text="Shape 5" />
        </DiagramShape>
        <DiagramShape Id="shape6">
            <DiagramShapeContent Text="Shape 6" />
        </DiagramShape>
    </DiagramShapes>

    <DiagramConnections>
        <DiagramConnection FromId="shape1" ToId="shape2" />
        <DiagramConnection FromId="shape1" ToId="shape3" />
        <DiagramConnection FromId="shape2" ToId="shape4" />
        <DiagramConnection FromId="shape2" ToId="shape5" />
        <DiagramConnection FromId="shape3" ToId="shape6" />
    </DiagramConnections>
</TelerikDiagram>

@code {
    private TelerikDiagram DiagramRef { get; set; }

    private async Task OnExportPdfClick()
    {
        var result = await DiagramRef!.ExportToPdfAsync(new PdfExportOptions
        {
            PaperSize = "A4",
            Landscape = true,
            Title = "Diagram Export"
        });

        var base64 = result.Substring(result.IndexOf(",") + 1);
        byte[] bytes = Convert.FromBase64String(base64);

        // The file is saved to the root application folder.
        System.IO.File.WriteAllBytes("diagram.pdf", bytes);
    }

    private async Task OnExportPngClick()
    {
        var result = await DiagramRef!.ExportToPngAsync();

        var base64 = result.Substring(result.IndexOf(",") + 1);
        byte[] bytes = Convert.FromBase64String(base64);

        // The file is saved to the root application folder.
        System.IO.File.WriteAllBytes("diagram.png", bytes);
    }
}

See Also