zoukankan      html  css  js  c++  java
  • C++ 打印XPS文档

     1 CoInitializeEx(0, COINIT_MULTITHREADED);
     2 
     3 IXpsOMObjectFactory *xpsFactory;
     4 
     5 HRESULT hr = CoCreateInstance(__uuidof(XpsOMObjectFactory), NULL, CLSCTX_INPROC_SERVER,__uuidof(IXpsOMObjectFactory),reinterpret_cast<LPVOID*>(&xpsFactory));
     6 
     7 IXpsOMPackage *package = NULL;
     8 
     9 std::tstring tstrFilename = _T("C:\MyXPSFile.xps");
    10 
    11 hr = xpsFactory->CreatePackageFromFile((LPCTSTR)tstrFilename.c_str(),FALSE,&package);
    12 
    13 HANDLE completionEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    14 
    15 IXpsPrintJob *job = NULL;
    16 IXpsPrintJobStream *jobStream = NULL;
    17 
    18 StartXpsPrintJob(_T("MyPrinter"),_T("Print Job 1"), NULL, NULL, completionEvent, NULL, 0, &job, &jobStream, NULL);
    19 
    20 hr = package->WriteToStream (jobStream, FALSE);
    21 
    22 hr = jobStream->Close();
    23 
    24 if (completionEvent != NULL)
    25 {
    26    if (WaitForSingleObject(completionEvent, INFINITE) == WAIT_OBJECT_0)
    27    {
    28       XPS_JOB_STATUS jobStatus;
    29       hr = job->GetJobStatus(&jobStatus);
    30    }
    31 
    32    CloseHandle(completionEvent);
    33    completionEvent = NULL;
    34 }
    35 
    36 jobStream->Release();
    37 jobStream = NULL;
    38 
    39 job->Release();
    40 job = NULL;
    41 
    42 package->Release();
    43 package = NULL;
  • 相关阅读:
    OCP-1Z0-053-V12.02-597题
    OCP-1Z0-053-V12.02-599题
    OCP-1Z0-053-V12.02-609题
    OCP-1Z0-053-V12.02-604题
    OCP-1Z0-053-V12.02-607题
    OCP-1Z0-053-V12.02-588题
    OCP-1Z0-053-V12.02-592题
    OCP-1Z0-053-V12.02-587题
    OCP-1Z0-053-V12.02-582题
    OCP-1Z0-053-V12.02-583题
  • 原文地址:https://www.cnblogs.com/guozht/p/11256090.html
Copyright © 2011-2022 走看看