Completed
Last Updated: 21 Feb 2023 14:05 by ADMIN
Release 4.1.0 (15/03/2023)
Gerald
Created on: 09 Jan 2023 01:02
Category: UI for Blazor
Type: Feature Request
1
Print Programmatically in the Blazor PDF Viewer

Hi,

Could you expose the Print Command of Blazor PDF Viewer? I would like to call it from within my code.

 

Regards

Gerald Man

1 comment
ADMIN
Dimo
Posted on: 11 Jan 2023 12:46

Hi Gerald,

Indeed, this suggestion makes sense, so I am marking it as Unplanned.

In the meantime, you can experiment with a JavaScript workaround that clicks the built-in print tool.

@inject IJSRuntime js

<TelerikButton OnClick="@OnPrintButtonClick">Print PDF</TelerikButton>

<TelerikPdfViewer Data="@PdfSource"
                  Height="600px">
</TelerikPdfViewer>

<script suppress-error="BL9992">
    function printPdf() {
        var printIcon = document.querySelector(".k-pdf-viewer .k-i-print");
        if (printIcon) {
            printIcon.parentNode.click();
        }
    }
</script>

@code {
    private byte[] PdfSource { get; set; }

    private async Task OnPrintButtonClick()
    {
        await js.InvokeVoidAsync("printPdf");
    }

    protected override void OnInitialized()
    {
        PdfSource = Convert.FromBase64String(PdfBase64);

        base.OnInitialized();
    }

    private const string PdfBase64 = "JVBERi0xLjEKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDEvTWVkaWFCb3ggWy00MCAtNjQgMjYwIDgwXSA+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL1BhcmVudCAyIDAgUi9SZXNvdXJjZXM8PC9Gb250PDwvRjE8PC9UeXBlL0ZvbnQvU3VidHlwZS9UeXBlMS9CYXNlRm9udC9BcmlhbD4+ID4+ID4+L0NvbnRlbnRzIDQgMCBSPj5lbmRvYmoKNCAwIG9iajw8L0xlbmd0aCA1OT4+CnN0cmVhbQpCVAovRjEgMTggVGYKMCAwIFRkCihUZWxlcmlrIFBkZlZpZXdlciBmb3IgQmxhem9yKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA1CjAwMDAwMDAwMDAgNjU1MzUgZgowMDAwMDAwMDIxIDAwMDAwIG4KMDAwMDAwMDA4NiAwMDAwMCBuCjAwMDAwMDAxOTUgMDAwMDAgbgowMDAwMDAwNDkwIDAwMDAwIG4KdHJhaWxlciA8PCAgL1Jvb3QgMSAwIFIgL1NpemUgNSA+PgpzdGFydHhyZWYKNjA5CiUlRU9G";
}

Regards,
Dimo
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.