Printing HTML progmatically
-
I wrote an app that creates a web page. Now they want to print it out. The problem comes that the settings for everyones printing is set differently, ie margins, header/footer, and if print background is selected. Is there a way to send IE the paramiters I want to print for this page? Thanks in advance. Darroll
-
I wrote an app that creates a web page. Now they want to print it out. The problem comes that the settings for everyones printing is set differently, ie margins, header/footer, and if print background is selected. Is there a way to send IE the paramiters I want to print for this page? Thanks in advance. Darroll
I've got a control derived from the browser. My printing code looks like this -
HRESULT hr; BSTR header\_BSTR = ::SysAllocString(L"&w&b&b&p"); VARIANT header\_variant; VariantInit(&header\_variant); V\_VT(&header\_variant) = VT\_BSTR; V\_BSTR(&header\_variant) = header\_BSTR; BSTR footer\_BSTR = ::SysAllocString(L"&d &t"); VARIANT footer\_variant; VariantInit(&footer\_variant); V\_VT(&footer\_variant) = VT\_BSTR; V\_BSTR(&footer\_variant) = footer\_BSTR; long index; SAFEARRAYBOUND parameter\_array\_bound\[1\]; SAFEARRAY \*parameter\_array = NULL; parameter\_array\_bound\[0\].cElements = 2; parameter\_array\_bound\[0\].lLbound = 0; parameter\_array = SafeArrayCreate(VT\_VARIANT,1,parameter\_array\_bound); index = 0; hr = SafeArrayPutElement(parameter\_array,&index,&header\_variant); index = 1; hr = SafeArrayPutElement(parameter\_array,&index,&footer\_variant); VARIANT parameter; VariantInit(¶meter); V\_VT(¶meter) = VT\_ARRAY | VT\_BYREF; V\_ARRAY(¶meter) = parameter\_array; hr = \_Browser->ExecWB(OLECMDID\_PRINT,OLECMDEXECOPT\_DONTPROMPTUSER,¶meter,NULL); if (!SUCCEEDED(hr)) { VariantClear(&header\_variant); VariantClear(&footer\_variant); if (parameter\_array != NULL) { SafeArrayDestroy(parameter\_array); } }
This code sets the header and footer for the page and then prints it. The
_Browser
value points to theIWebBrowser2
interface for the control. If I remember correctly, I found this stuff in an example in the MSDN.
Software Zen:
delete this;