i am need of a method to open a print dialog and print a particular div. I am only using the windows platform. something i can use on a button click.
Printing a div in .net maui blazor app.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Mohammad HussainRank #513 · 4.8K reputationPosted Aug 2, 2023, 11:50 AM EDT
Print function printDiv() { // Get the div element you want to print var divToPrint = document.getElementById('printDivFunction'); // Create a new window for printing var printWindow = window.open('', '', 'height=400,width=600'); // Write the div's content into the new window printWindow.document.write('Print'); printWindow.document.write(divToPrint.innerHTML); printWindow.document.write(''); // Print the content in the new window printWindow.print(); // Close the new window after printing printWindow.close(); }@code { private async Task PrintDiv() { await JSRuntime.InvokeVoidAsync("printDivFunction"); } }