Aspose.Diagram.Examples.CSharp.Working_with_Print.XpsPrintHelper.Print C# (CSharp) Метод

Print() публичный статический Метод

Sends a stream that contains a document in the XPS format to a printer using the XpsPrint API. Has no dependency on Aspose.Diagram, can be used in any project.
Thrown if any error occurs.
public static Print ( Stream stream, string printerName, string jobName, bool isWait ) : void
stream Stream
printerName string
jobName string Job name. Can be null.
isWait bool True to wait for the job to complete. False to return immediately after submitting the job.
Результат void
        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

Same methods

XpsPrintHelper::Print ( Diagram diagram, string printerName, string jobName, bool isWait ) : void

Usage Example

        public static void Run()
        {
            // ExStart:PrintDiagramVisXPSPrinterAPI
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Print();

            // Load source Visio diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");

            // Specify the name of the printer you want to print to.
            const string printerName = @"\\COMPANY\Brother MFC-885CW Printer";

            // Print the document.
            XpsPrintHelper.Print(diagram, printerName, "My Test Job", true);
            // ExEnd:PrintDiagramVisXPSPrinterAPI
        }