C++ 打印XPS文档
Posted guozht
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
以上是关于C++ 打印XPS文档的主要内容,如果未能解决你的问题,请参考以下文章