Eu sei que a resposta já foi fornecida. Mas eu só queria elaborar com relação a fazer isso em um aplicativo Blazor (navalha) ...
Você precisará injetar IJSRuntime, para executar JSInterop (executando funções javascript em C #)
EM SUA PÁGINA RAZOR:
@inject IJSRuntime JSRuntime
Depois de injetar isso, crie um botão com um evento click que chame um método C #:
<MatFAB Icon="@MatIconNames.Print" OnClick="@(async () => await print())"></MatFAB>
(ou algo mais simples se você não usar o MatBlazor)
<button @onclick="@(async () => await print())">PRINT</button>
Para o método C #:
public async Task print()
{
await JSRuntime.InvokeVoidAsync("printDocument");
}
AGORA EM SEU index.html:
<script>
function printDocument() {
window.print();
}
</script>
Algo a ser observado, a razão pela qual os eventos onclick são assíncronos é porque o IJSRuntime aguarda chamadas como InvokeVoidAsync
PS: Se você quiser enviar uma caixa de mensagens no asp net core, por exemplo:
await JSRuntime.InvokeAsync<string>("alert", "Hello user, this is the message box");
Para ter uma caixa de mensagem de confirmação:
bool question = await JSRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to do this?");
if(question == true)
{
//user clicked yes
}
else
{
//user clicked no
}
Espero que isto ajude :)