public static void Print(Stream stream, string printerName, string jobName, bool isWait)
{
if (stream == null)
throw new ArgumentNullException("stream");
if (printerName == null)
throw new ArgumentNullException("printerName");
// Create an event that we will wait on until the job is complete.
IntPtr completionEvent = CreateEvent(IntPtr.Zero, true, false, null);
if (completionEvent == IntPtr.Zero)
throw new Win32Exception();
try
{
IXpsPrintJob job;
IXpsPrintJobStream jobStream;
StartJob(printerName, jobName, completionEvent, out job, out jobStream);
CopyJob(stream, job, jobStream);
if (isWait)
{
WaitForJob(completionEvent);
CheckJobStatus(job);
}
}
finally
{
if (completionEvent != IntPtr.Zero)
CloseHandle(completionEvent);
}
}
// ExEnd:XpsPrint_PrintStream