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.
Related
I'm creating a C# ASP.NET website and from it I would like to launch the TeamViewer desktop application.
I've read around that there are security implications for this and that browsers may not allow this to prevent websites from taking control of computers (correct me if I'm wrong), however, if I log in to TeamViewer's Management Console, and try to connect to one of my registered devices, the website will try to launch TeamViewer, as seen below:
1.
2.
I'm not looking to launch any features of TeamViewer, only to launch the application and that's it. Is this possible using either C# or JavaScript? I would like this to work cross-platform and cross-browser as well.
Here is a similar question I've came across.
I would like to be able to know when arbitrary JavaScript successfully executes a command in a web browser. The medium doesn't matter, it could be a log, stack trace, event signal, it just has to be something that can be programmatically analyzed.
I've thought about this problem for some time now and I have not been able to come up with an adequate solution. I'm no expert with JavaScript though, so I'm wondering what ideas you have?
Since you'll probably be wondering why, it's just something I'm very interested in.
Any input is appreciated. Can you help me?
EDIT: I've investigated using something like Firebug to monitor JavaScript functions, however I wasn't able to determine if Firebug can be run programmatically on a simulated Web Browser (like a web-browser control in ASP.NET, which is what I'm currently using.) Does anyone know if it can?
You can use the profiler of Firebug.
Go to the console tab and click Profile. The profiler starts and all the javascript actions are "logged" till you click Profile again. Then you get the list of javascript functions that were executed in this interval.
A similar feature is available in most modern browsers' consoles.
Source: See/Log which javascript function is being executed by the browser
The firefox browser could be used in asp .net using the selenium web driver and it also provide the ability to access all details from a web page. see the document and download api code and integrate it in your project its very easy to integrate using its help.
http://docs.seleniumhq.org/projects/webdriver/
This answer shows how to enable silent printing in Google Chrome. However, I have two web pages which have to be silently printed using two different printers without further user interaction. Is there a way to select a printer automatically before calling window.print()? I don’t mind writing a Chrome Extension if really necessary.
Maybe you could setup your printers with Google Clound Print then use the cloud printing API to silently submit jobs to them. It looks like you can specify the printer id when you submit the job. You might need to use something like html2canvas to rasterize the webpage.
If you are in an environment that you know, and in wich you have enough privileges (i suppose, since you know the printer you want to use) you can try to change it through the command line.
For this, you should call
#RunDLL32.EXE printui.dll,PrintUIEntry /y /n "Printer name"
The printer name has to be the value displayed in the control panel.
For calling command line from javascript, if you have the proper ActiveX controls enabled, you can use:
var run=new ActiveXObject('WSCRIPT.Shell').Run("commands to run");
also, you can try with shell.application ShellExecute
var objShell = new ActiveXObject("shell.application");
objShell.ShellExecute("cmd.exe", 'RunDLL32.EXE printui.dll,PrintUIEntry /y /n "Printer name"', "C:\\WINDOWS\\system32", "open", 1);
For more information you can go to http://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx
I havent tested it, so good luck!
I ended up writing a server in F# and communicating with that through a WebSocket.
I have searched for an answer but it looks like there is no way to set a printer programatically. Therefore my probably complicated solution:
Create a command line application which can switch the default printer of the operating system. Maybe an application which is capable of disabling and enabling a printer. If you are on Windows a .NET application could probably do this. If on Linux there should be a command line interface for printer management (I don't know for sure).
Now make for example a PHP, asp.net or ruby etc. page which is able to call the printer enable/disable program.
If this is working you can use Javascript calls to first print to printer one and after the switch to printer two. However there some disadvantages:
If printer one is printing a document you can not switch to printer two, since this will disable printer one. So somehow you should time how long a common job takes.
There is a lot of overhead in this solution. You need to made extra calls for the switch between printers
Maintainability is absolutely not optimal since you need to maintain the printer switch program and the webservice.
I hope for you someone comes up with a better solution, but I wanted to at least share my thoughts. Maybe they help you in solving your problem.
If you're doing this for a product or webapp that will run in an environment where there are printers etc. A better solution to just giving clients a webappp to run might be to wrap your webapp with a desktop application using Chromium Embedded Framework. Like Chromely (kind of like Electron, but lighter), EdgeSharp or CEFSharp etc.
Using this technique, you can write code that can actually enumerate printers on the network and talk to hardware while still running your webapp and you can expose new JS api's you build in the desktop app to your web application.
Then to make it smart, you can have your webapp work in both environments, running in the desktop app, or directly in a browser. Where it would have advanced extended features running in the desktop application.
Then you can deploy said application a plethora of ways. For example, Windows 10+ you can have a private windows Store for your company and you can deploy the application to your private windows store where it can be installed via the Private Windows Store which you can setup with Group Policies on Windows.
Or you could have a private npm repo and script the install/update of your application. Even old school techniques like Microsoft Click Once installs, and on and on.
But the most power you can possibly give your web application is to give it a custom browser to run on and with Chromium Embedded Framework it's so easy.
In C# you can spin up a simple Chrome wrapper in less than 60 seconds.
Using .Net 6+ and EdgeSharp for example, you could get this to be cross platform on Linux, Windows, and MacOsx, and also port it to Xamarin and IOS pretty easily so that you can have this power on phones, pc's, mac's, and tablets.
Is it possible writing a cross-platform desktop application with XHTML (or HTML), CSS and JavaScript?
If the answer is yes, how to run this application? Should I run it with a browser like Firefox?
Note: Currently Windows supports HTML Application.
It seems that what you're looking for is the Open Web Apps
HTA is really Old technology.
Try tools like Titanium (Appcelerator). They are tools, which render HTML content inside an APP. So, from outside, you will be running an executable but inside , it is loading a HTML file.
Same principle is being used in many apps now a days. Facebook for android is a best example
If client-side JavaScript, and/or HTML/CSS hackery accomplishes the task you wish it to, yes, and with a user agent like Firefox, indeed.
Yes. With HTML5.
The other answer's solutions are great, but generally they assume that the user is connected to the internet to have a server-side that handles the data.
But it's possible to use Open Web Apps (as ZER0 suggested) with HTML5, which has a lot of support for offline web apps.
Pay attention to it, though. Even HTML5 assumes that eventually the user will have some sort of internet connection, and offline functionalities are seen as a "cache". So, I'm not sure that this solution is enough for every requirement, because I don't know how much space HTML5 provides to offline applications
I need some expert information about ActiveX and some valuable experience reports from those that already used it.
The situation is the following: ~90% of all of our applications are created as web apps with ASP.net WebForms. We're now in the process of switching to a more modern approach, creating rich client JavaScript apps. However, In one of the recent projects, a strong requirement from the customer is the ability to directly print to a (previously configured) printer attached to the user's workstation. Yes, no printer dialogs, print previews etc.. It has to be fast.
Obviously this is a scenario where you would rather use a desktop app than a web based one. Still, we would like to benefit from our existing web dev knowledge and are therefore considering to write that very specific, isolated printing functionality as an ActiveX control (IE dependency is not an issue).
Now, since the word "ActiveX" alone causes disgust for some people, I'd like to hear what might be the potential problems at using such a (old) technology or do u directly consider me to make it as a desktop app and completely forget about it?? Or are there alternatives??
The primary challenge you'll face is the learning curve; beyond that the biggest problems are the potential for you messing up and opening a security hole (for example, what happens if a malicious third party loads your activex control on their phishing site? can they use it to print things?), etc.
For the learning curve, I highly recommend looking at FireBreath, which can be used to create browser plugins that work on IE (as an ActiveX control) as well as Firefox, chrome, safari, etc (as a NPAPI plugin). Though ActiveX is an "old" technology, it's still used extensively in the modern day; for example, Flash, Silverlight, Quicktime, and other "plugins" like that are all activex controls in IE.