Print Dialog "Print To File"
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
Hi, Programmatically, Instead of standard printer, I want to print report to a file ("Print To File" option in Print Dialog). I use IWebBrowser to navigate the report in my code. 1. I have a report file, XML and XSL based report, viewable in IE. 2. In my program, I use IWebBrowser to navigate report in background, before sending it to standard printer. 3. Now I want to print this report to a file programmaticaly, ("Print To File"). Please refer sample code below,
void PrintReport(CString strReportName, OLECMDEXECOPT enumPrompt) { ::OleInitialize(NULL); void PrintReport(CString strReportName, OLECMDEXECOPT enumPrompt) { ::OleInitialize(NULL); try { SHDocVw::IWebBrowserAppPtr ptrWebBrowserApp(__uuidof(SHDocVw::InternetExplorer)); SHDocVw::IWebBrowser2Ptr ptrWebBrowser = ptrWebBrowserApp; _variant_t vtDummy; HRESULT hr = E_FAIL; BSTR bUrl = strReportName.AllocSysString(); hr = ptrWebBrowser->Navigate(bUrl, &vtDummy, &vtDummy, &vtDummy, &vtDummy); VARIANT_BOOL bBool = ptrWebBrowser->Busy; while(ptrWebBrowser->Busy == VARIANT_TRUE) { ::Sleep(1000); } IOleCommandTargetPtr ptrOleCmdTarget = ptrWebBrowser->Document; // Here I want to "Print To File" directly, without any prompt. hr = ptrOleCmdTarget->Exec(NULL, OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER /*OLECMDEXECOPT_PROMPTUSER*/, NULL,NULL); } catch(_com_error& e) { _ftprintf(stderr, _T("Error: 0x%08X (%s); Source: %ls; Desc: %ls"), e.Error(), e.ErrorMessage(), LPCWSTR(e.Source()), LPCWSTR(e.Description()) ); } ::OleUninitialize(); }
Any help would be highly appreciable. Regards, Paresh.