8

I have a view with HTML tables, filled with information that I want to print in ASP.NET MVC 4 and C#.

I don't know the actual code that prints the document, any help will be appreciated

Ryan McDonough
  • 9,467
  • 3
  • 53
  • 75
RobertKing
  • 1,783
  • 8
  • 28
  • 54
  • Print manually in the browser or create for example a PDF and send it to a printer? – Alex Jul 09 '13 at 09:16

1 Answers1

17

Well you have two choices

  1. Either use JS

    <a href="javascript:window.print()">Click to Print This Page</a>

  2. Or print to a PDF using Action Result in MVC

For the JS option you will want to build a print css file so as to best render the page during printing, also hide some element that you don't need to appear - menus for example.

Patrick McDonald
  • 62,076
  • 14
  • 100
  • 117
Ryan McDonough
  • 9,467
  • 3
  • 53
  • 75
  • For some reason the editor window didn't want to format the code properly... Feel free to edit it, may be a chrome issue? – Ryan McDonough Jul 09 '13 at 09:23
  • 1
    how can i print a div only(in case i dont want to include the menus and other thing came from master page).. – RobertKing Jul 09 '13 at 09:26
  • 1
    If you check that print css link and look at the Remove unwanted items section, essentially you have a .noprint {display: none;} class and put that on all the items you don't want to show. Then put .noprint only in your print stylesheet. – Ryan McDonough Jul 09 '13 at 09:28