Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Print Dialog "Print To File"

Print Dialog "Print To File"

Scheduled Pinned Locked Moved C / C++ / MFC
xmlhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paresh Chitte
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups