1

I have a web app developed which needs to do silent printing on various platforms. For Windows, I was thinking to set up a WinForms project, wrap the web app with WebBrowser control.

My question is, how can I interact between the pages displayed in the WebBrowser control and the native WinForms C# code to print.

I need to be able to select which printer to use and it needs to be 'silent', that is, no additional pop-ups.

If there are better (or other) ways of doing it, please let me know too.

Any thoughts, or code samples would be great, thanks.

PostureOfLearning
  • 3,481
  • 3
  • 27
  • 44
  • If I could find my printing code on my HDD, I will post it for you, but it doesn't print from a Web Browser control, but it is WinForms, and I'm sure it would be pretty easy to adapt the code to your needs. Let me know if this would be alright. – username Nov 09 '15 at 11:34
  • Have you tried the actual Print() method on the WebBrowser control? As i recall it invokes the standard printing hidden in the actual renderer. If you really need a custom print solution, then an option is to take the document as is (meaning the html in the view) then render it for printing yourself. – Richard Tyregrim Nov 09 '15 at 11:39
  • @RichardEriksson The issue is being able to invoke the print() method using a 'trigger' (i.e. a button on web page) from withing the web app/page. How do I do this? – PostureOfLearning Nov 09 '15 at 11:48
  • @popshuvit, I can print from a WinForm but I need to do it from the Web interface. If that is what you have, then yes, I would appreciate it. – PostureOfLearning Nov 09 '15 at 11:50
  • @PostureOfLearning Ok, I understand now. The code I have is strictly winforms. However, I did find this: http://stackoverflow.com/questions/1096862/print-directly-from-browser-without-print-popup-window which prints without confirmation. It works in IE using VBScript (I know...). Not sure about other browsers. – username Nov 09 '15 at 11:55
  • @popshuvit I need to print silently (no pop-up dialog) to a specific printer (not default). I don't think this can be done from a web page due to security reasons etc. That is why I was thinking to wrap it in WinForms. However, if there is a way to do this directly from a regular browser this will work for me too. – PostureOfLearning Nov 09 '15 at 12:13
  • In that case i would say you may need to render for printing yourself... So that you take the page data from the control, which will be the entire html structure. Then you can parse this to a printable format by some lifting, so that you replace all tags with text formatting (it will be a string) and get rid of others, like JS and the like. Then fire printing from the formas application. Look at the DocumentText property of the WebBrowser control, it should contain the full document. – Richard Tyregrim Nov 09 '15 at 13:58

0 Answers0