How to print a View to a standard printer using Javascript or c#?

Asked

Viewed 1,208 times

4

I need to print the contents of a view on the default printer. How can I do this using c# or javascript?

1 answer

1

An alternative is you call the function print() of JavaScript. That would be your code:

This CSS only serves to not show the print button by clicking on it

@media print
{    
    .no-print, .no-print *
    {
        display: none !important;
    }
}

And in his View you add the print button

<div>
   <h3>Teste Impressão!</h3>
</div> 

<div class="no-print">
    <button type="button" value="imprimir" onclick="window.print();">Imprimir</button>
</div>

And in his View you add the print button.

You can see the example working on Dotnetfiddle.

  • Blz plus the content to be printed will be from my view ?

  • @Hansmiller content will be whatever is in your View.

  • @Hansmiller I edited the answer with an example.

  • has how to make the command print directly or is automatically not needing to confirm the printer?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.