public string GetPrinter() { if (GetPrinterList() == null) { return(null); } string printerName = null; IEnumerator <PrintQueue> e = printerList.GetEnumerator(); if (e.MoveNext()) { printerName = e.Current.FullName; } return(printerName); }
} //Fin PrinterProperties() /** * \brief Se establecen las propiedades de las impresoras gestionadas por el Servidor de impresión * \details La única propiedad que nos interesa establecer y mantener para poder monitorizar los trabajos de impresión es que * "Conserven los documentos después de su impresión" (Se conserven los ficheros de Spool) */ public static void ConfigurePrinters() { PrintQueue printQueue = null; LocalPrintServer localPrintServer; try { /// Accedemos al Servidor de Impresión Local localPrintServer = new LocalPrintServer(); Log.Debug(">>> Servidor de impresion: '" + localPrintServer.Name + "'"); /// Accedemos a las impresoras gestionadas por el Servidor de Impresión Local PrintQueueCollection localPrinterCollection = localPrintServer.GetPrintQueues(); System.Collections.IEnumerator localPrinterEnumerator = localPrinterCollection.GetEnumerator(); /// Recorremos todas las impresoras y revisamos su configuración para que se conserven los ficheros de Spool while (localPrinterEnumerator.MoveNext()) { printQueue = (PrintQueue)localPrinterEnumerator.Current; ApiImpresion PrintServer = new ApiImpresion(); PrintServer.KeepSpoolFiles(printQueue.Name); printQueue.Refresh(); } //while } catch (Exception e) { Log.Error(e); } //try } //ConfigurePrinters()
public Collection <PrintQueue> GetAllPrinter() { PrintQueue printQueue1 = null; LocalPrintServer localPrintServer1 = new LocalPrintServer(); // Retrieving collection of local printer on user machine PrintQueueCollection localPrinterCollection1 = localPrintServer1.GetPrintQueues(); //printQueue = localPrintServer.DefaultPrintQueue; IEnumerator <PrintQueue> all = localPrinterCollection1.GetEnumerator(); Collection <PrintQueue> AllPrinter = new Collection <PrintQueue>(); while (all.MoveNext()) { printQueue1 = all.Current; // this.comboBox1.Items.Add(printQueue.FullName); AllPrinter.Add(all.Current); } return(AllPrinter); }
private void InitializePrinterGallery() { GalleryItem defaultPrinter = null; try { LocalPrintServer localPrintServer = new LocalPrintServer(); PrintQueueCollection localPrinterCollection = localPrintServer.GetPrintQueues(); System.Collections.IEnumerator localPrinterEnumerator = localPrinterCollection.GetEnumerator(); while (localPrinterEnumerator.MoveNext()) { GalleryItem item = new GalleryItem(); item.Image = PhotoAssistant.UI.Properties.Resources.print_32x32; PrintQueue queue = ((PrintQueue)localPrinterEnumerator.Current); item.Caption = queue.FullName; item.Description = queue.Description; item.Value = queue; this.gcPrinter.Gallery.Groups[0].Items.Add(item); if (queue == localPrintServer.DefaultPrintQueue) { defaultPrinter = item; } } } catch { } this.gcPrinter.Gallery.ItemCheckedChanged += new GalleryItemEventHandler(OnPrinterGalleryItemCheckedChanged); if (defaultPrinter != null) { defaultPrinter.Checked = true; } }
private PrintTicket GetPrintTicketFromPrinter(Report_Template printerSettings) { PrintQueue printQueue = null; LocalPrintServer localPrintServer = new LocalPrintServer(); // Retrieving collection of local printer on user machine PrintQueueCollection localPrinterCollection = localPrintServer.GetPrintQueues(); System.Collections.IEnumerator localPrinterEnumerator = localPrinterCollection.GetEnumerator(); if (localPrinterEnumerator.MoveNext()) { // Get PrintQueue from first available printer printQueue = (PrintQueue)localPrinterEnumerator.Current; MessageBox.Show(printQueue.Name); } else { // No printer exist, return null PrintTicket return(null); } // Get default PrintTicket from printer PrintTicket printTicket = printQueue.DefaultPrintTicket; PrintCapabilities printCapabilites = printQueue.GetPrintCapabilities(); // Modify PrintTicket if (printCapabilites.CollationCapability.Contains(Collation.Collated)) { printTicket.Collation = Collation.Collated; } if (printCapabilites.DuplexingCapability.Contains( Duplexing.TwoSidedLongEdge)) { printTicket.Duplexing = Duplexing.TwoSidedLongEdge; } if (printCapabilites.StaplingCapability.Contains(Stapling.StapleDualLeft)) { printTicket.Stapling = Stapling.StapleDualLeft; } printTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.JISB4); printTicket.PageOrientation = PageOrientation.Unknown; printTicket.Duplexing = Duplexing.TwoSidedShortEdge; printTicket.PageResolution = new PageResolution(PageQualitativeResolution.Draft); return(printTicket); }// end:GetPrintTicketFromPrinter()
private void GetPrintTicketFromPrinter() { PrintQueue printQueue = null; LocalPrintServer localPrintServer = new LocalPrintServer(); // Retrieving collection of local printer on user machine PrintQueueCollection localPrinterCollection = localPrintServer.GetPrintQueues(); System.Collections.IEnumerator localPrinterEnumerator = localPrinterCollection.GetEnumerator(); while (localPrinterEnumerator.MoveNext()) { // Get PrintQueue from first available printer printQueue = (PrintQueue)localPrinterEnumerator.Current; } //else //{ // // No printer exist, return null PrintTicket // return ; //} return; // Get default PrintTicket from printer //PrintTicket printTicket = printQueue.DefaultPrintTicket; //PrintCapabilities printCapabilites = printQueue.GetPrintCapabilities(); //// Modify PrintTicket //if (printCapabilites.CollationCapability.Contains(Collation.Collated)) //{ // printTicket.Collation = Collation.Collated; //} //if (printCapabilites.DuplexingCapability.Contains( // Duplexing.TwoSidedLongEdge)) //{ // printTicket.Duplexing = Duplexing.TwoSidedLongEdge; //} //if (printCapabilites.StaplingCapability.Contains(Stapling.StapleDualLeft)) //{ // printTicket.Stapling = Stapling.StapleDualLeft; //} //return printTicket; }// end:GetPrintTicketFromPrinter()
private PrintQueue GetPrintQueue(string printername) { LocalPrintServer localPrintServer = new LocalPrintServer(); // Retrieving collection of local printers on user's machine PrintQueueCollection localPrinterCollection = localPrintServer.GetPrintQueues(); System.Collections.IEnumerator localPrinterEnumerator = localPrinterCollection.GetEnumerator(); while (localPrinterEnumerator.MoveNext()) { if (((PrintQueue)localPrinterEnumerator.Current).FullName == printername) { return((PrintQueue)localPrinterEnumerator.Current); } } return(null); }
private void GetPrinters() { LocalPrintServer localPrintServer = new LocalPrintServer(); // Retrieving collection of local printers on user's machine PrintQueueCollection localPrinterCollection = localPrintServer.GetPrintQueues(); System.Collections.IEnumerator localPrinterEnumerator = localPrinterCollection.GetEnumerator(); int index = 0; int defindx = -1; PrintQueue printer = LocalPrintServer.GetDefaultPrintQueue(); while (localPrinterEnumerator.MoveNext()) { printers.Items.Add(((PrintQueue)localPrinterEnumerator.Current).FullName); if (((PrintQueue)localPrinterEnumerator.Current).FullName == printer.FullName) { defindx = index; } index++; } printers.SelectedIndex = defindx; }
private void frmPrintPreView_Load(object sender, EventArgs e) { int i; string defultPrinterName = ""; try { var printDoc = new PrintDocument(); for (i = 0; i < PrinterSettings.InstalledPrinters.Count; i++) { // pkInstalledPrinters = PrinterSettings.InstalledPrinters[i]; // comboInstalledPrinters.Items.Add(pkInstalledPrinters); if (printDoc.PrinterSettings.IsDefaultPrinter) { defultPrinterName = printDoc.PrinterSettings.PrinterName; break; } } } catch { } try { var localPrintServer1 = new PrintServer(); } catch { MessageBox.Show("invalid Framwork 3.5"); } try { PrintQueue printQueue = null; var localPrintServer = new PrintServer(); var FiltterPrinterType = new EnumeratedPrintQueueTypes[2]; FiltterPrinterType[0] = EnumeratedPrintQueueTypes.Connections; FiltterPrinterType[1] = EnumeratedPrintQueueTypes.Local; // Retrieving collection of local printer on user machine var localPrinterCollection = new PrintQueueCollection(); try { localPrinterCollection = localPrintServer.GetPrintQueues(FiltterPrinterType); } catch { MessageBox.Show("vvv"); } //printQueue = localPrintServer.; IEnumerator<PrintQueue> all = null; try { all = localPrinterCollection.GetEnumerator(); } catch { MessageBox.Show("ss"); } var AllPrinter = new Collection<PrintQueue>(); PrintQueue defultPrinter = null; while (all.MoveNext()) { try { // printQueue = all.Current; // if (printQueue.DefaultPrintTicket ) // this.comboBox1.Items.Add(printQueue.FullName); if (defultPrinterName == all.Current.Name) { defultPrinter = all.Current; } AllPrinter.Add(all.Current); } catch { MessageBox.Show("kkk"); } } //System.Printing.LocalPrintServer lPrint = new System.Printing.LocalPrintServer(); //System.Printing.PrintQueueCollection pCol = lPrint.GetPrintQueues(); try { cmbPrinters.DataSource = AllPrinter; cmbPrinters.DisplayMember = "FullName"; try { if (defultPrinter != null) { this.cmbPrinters.SelectedItem = defultPrinter; } } catch { } } catch { MessageBox.Show("tttt"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Image = CurrentViewImage;// AllImage[0]; rbtnCurrentView.Checked = true; // cmbPrinters.Enabled = true; cboxFitToPage.Checked = true; cboxCenter.Checked = true; }