Printing a web page
-
I am looking for a way to print and html page from an embeded web browser window. Is there an easy way to do this. I created the document because I did not want to go through all the trouble of designing my own print function to do every line and all the text on the page.
-
I am looking for a way to print and html page from an embeded web browser window. Is there an easy way to do this. I created the document because I did not want to go through all the trouble of designing my own print function to do every line and all the text on the page.
Call
AxWebBrowser.ExecWB
withOLECMDID.OLECMDID_PRINT
, and with theOLECMDEXECOPT
enumeration you want (likeOLECMDEXECOPT.OLECMDEXECOPT_PROMPT
to show the print UI). If you read the documentation for the IDM_PRINT[^] (works the same asOLECMDID_PRINT
), you can see what you can pass for thepvaIn
andpvaOut
params. For instance, to just print the page using the default printer without showing the UI, you could do the following:object pvaIn = 1; // PRINT_DONTBOTHERUSER
object pvaOut = null;
axWebBrowser1.ExecWB(OLECMDID.OLECMDID_PRINT,
OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref pvaIn, ref pvaOut);Executing commands on the
AxWebBrowser
control (from creating an ActiveX interop assembly on the shdocvw.dll library, as is common) is the same as getting theIOleCommandTarget
, which does the same functionality as using the various commands from the Internet Explorer (iexplore.exe) application. So, if you passed parameters to prompt the user to pick a printer and change other options, it would be the same as File-<Print in Internet Explorer.Microsoft MVP, Visual C# My Articles
-
I am looking for a way to print and html page from an embeded web browser window. Is there an easy way to do this. I created the document because I did not want to go through all the trouble of designing my own print function to do every line and all the text on the page.
You should be able to just use javascript:
window.print();
Michael Flanakin Web Log