Answer the question
In order to leave comments, you need to log in
Programmatically selecting a printer for printing from the WebBrowser component
Good time of the day!
you need to programmatically send a document for printing located in the WebBrowser, and to a printer that is not the default printer in the system.
I know how to programmatically call the printer selection dialog, you need to programmatically select.
I also know how to change the default printer programmatically and then return it to its place (this option is now working), but I would like not to change the default printer.
It is clear that I also know how to send to print.
It would be ideal to somehow connect WebBroser and System.Drawing.Printing.PrintDocument in which the choice of printer does not raise questions.
Please let me know if someone has dealt with this problem before.
Thank you.
Answer the question
In order to leave comments, you need to log in
Hello,
If I understand correctly, you need to send a command to the C# code from the page loaded in the WebBrowser control to set up the printer and print. If so, then your question is how to call this code from the page. See here . The printer is set through the System.Drawing.Printing.PrintDocument.PrinterSettings.PrinterName property, without dialogs.
Or specify what exactly you want.
The idea of using JavaScript in a document to send printing from WebControl to the desired printer while working in Sharpe smells like a big crutch, I’m silent that this script will have to be stuffed into each document.
Perhaps I did not describe the task well enough:
The main idea is to load an html page into the WebBrowser control while in Sharpe and send it to the desired printer while being in Sharpe all the time. Through JavaScript, of course, you can, but it hurts like everything smells of perversion. And how do you imagine setting up a printer through System.Drawing.Printing.PrintDocument.PrinterSettings.PrinterName if the PrintDocument and the document located in the WebBrowser are not connected in any way?
It looks like I was in a hurry to advise PrintDocument. I also found a way, but like you, through changing the default printer. Do not tell me how stable this option works, or just have a desire to do it more correctly?
First of all, it's just ugly. Secondly, the default printer change is delayed (especially on the first call). You have to do a loop with a poll and wait for the change to occur. Again, hypothetically, if someone wants to print in parallel and is waiting for another default printer, etc. The project is serious and I don’t want to write crutches.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question