private void button1_Click(object sender, RoutedEventArgs e) { #region #xpfprinter RichEditDocumentServer srv = new RichEditDocumentServer(); srv.LoadDocument("test.docx"); FixedDocument document = RichEditDocumentXpfPrinter.CreateFixedDocument(srv); PrintDialog pDialog = new PrintDialog(); PrintQueueCollection queues = new PrintServer().GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections }); System.Collections.IEnumerator localPrinterEnumerator = queues.GetEnumerator(); PrintQueue printQueue = null; do { if (!localPrinterEnumerator.MoveNext()) { break; } printQueue = (PrintQueue)localPrinterEnumerator.Current; }while (!printQueue.FullName.Contains("Canon")); if (printQueue != null) { pDialog.PrintQueue = printQueue; pDialog.PrintDocument(document.DocumentPaginator, string.Empty); } #endregion #xpfprinter }
public void PrintToMyPrinter() { PrintDialog pDialog = new PrintDialog(); PrintQueueCollection queues = new PrintServer().GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections }); System.Collections.IEnumerator localPrinterEnumerator = queues.GetEnumerator(); PrintQueue printQueue = null; if (localPrinterEnumerator.MoveNext()) { printQueue = (PrintQueue)localPrinterEnumerator.Current; } if (printQueue != null) { pDialog.PrintQueue = printQueue; FixedDocument document = this.CreateFixedDocument(); pDialog.PrintDocument(document.DocumentPaginator, string.Empty); } }