Is there a way for me to pass a PrintDlg structure (or something similar) to my WebBrowser (Internet Explorer / IWebBrowser2) control such that it will print to the printer specified in the PrintDlg without popping up a print dialog? I want to do this without changing the default printer. IWebBrowser2::ExecWB provides a way to skip the dialog pop-up (OLECMDEXECOPT_DONTPROMPTUSER), but not a way to specify a printer.
There are two problems with just changing the default printer: 1) it's slow, 2) Internet Explorer keeps its current printer cached. When you print to the default printer, it will cache that printer. If you then change the default printer and tell it to print again, IE will not use the new default printer, it will used its cached current printer.
After IE 5.5, the current printer is not stored in the Windows registry.
As an alternative, I researched 4 different ideas for getting the image from the IE control and printing myself rather than getting the control to print itself:
Using IViewObject::Draw. I can get the image, but can't get it to scale to paper the same way that it does when printed for IE:
RECTL rect;
rect.left = 0;
rect.top = 0;
rect.right = GetDeviceCaps(printerhdc, PHYSICALWIDTH);
rect.bottom = GetDeviceCaps(printerhdc, PHYSICALHEIGHT);StartDoc(printerhdc, &di);
StartPage(printerhdc);
HRESULT hr = pViewObj->Draw(DVASPECT_DOCPRINT, page, NULL, pTargetDevice, printerhdc, printerhdc, &rect, NULL, NULL, 0); //prints too small
EndPage(printerhdc);
EndDoc(printerhdc);Sending a WM_PAINT to the IE control. I haven't done much with this one, as I read in a thread online that this didn't work that well.
AxDHTMLEDLib. Very little documentation, and I think this is just for .net
Using IHTMLElement, IHTMLElementRender->SetDocumentPrinter, IHTMLElementRender->DrawToDc. Microsoft has withdrawn support with IE9
Any ideas you may have would be wildly appreciated! Thanks in advance!