Aspose.Plugins.AsposeVSOpenXML.XpsPrintHelper.Print C# (CSharp) Method

Print() public static method

Sends an Aspose.Words document to a printer using the XpsPrint API.
Thrown if any error occurs.
public static Print ( Aspose document, string printerName, string jobName, bool isWait ) : void
document Aspose
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.
return void
        public static void Print(Aspose.Words.Document document, string printerName, string jobName, bool isWait)
        {
            if (document == null)
                throw new ArgumentNullException("document");

            // Use Aspose.Words to convert the document to XPS and store in a memory stream.
            MemoryStream stream = new MemoryStream();
            document.Save(stream, Aspose.Words.SaveFormat.Xps);
            stream.Position = 0;

            Print(stream, printerName, jobName, isWait);
        }
//ExEnd

Same methods

XpsPrintHelper::Print ( Stream stream, string printerName, string jobName, bool isWait ) : void

Usage Example

Beispiel #1
0
        public static void Main(string[] args)
        {
            try
            {
                // Sample infrastructure.
                string exeDir  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
                string dataDir = new Uri(new Uri(exeDir), @"../Data/").LocalPath;
                //ExStart
                //ExId:XpsPrint_Main
                //ExSummary:Invoke the utility class to print via XPS.
                // Open a sample document in Aspose.Words.
                Aspose.Words.Document document = new Aspose.Words.Document(dataDir + "Print via XPS API.doc");

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

                // Print the document.
                XpsPrintHelper.Print(document, printerName, "test", true);
                //ExEnd
                Console.WriteLine("Printed successfully.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.WriteLine("Press Enter.");
            Console.ReadLine();
        }