} // End DockTheCard private void PrintCard() { StandardPrintController spController = new StandardPrintController(); // Subscribe to the print event printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); // Use selected printer. printDocument.PrinterSettings.PrinterName = m_selectedPrinter; //// To allow to change printer instance //// Pass the PrintDocument object in so that the dialog can update the printer name //// and devmode for this job. //PrintDialog dlgSettings = new PrintDialog(); //dlgSettings.Document = m_printDocument; //dlgSettings.ShowDialog(); m_iPageNumber = 1; m_iNumPages = 2; printDocument.QueryPageSettings += new QueryPageSettingsEventHandler(printDocument_QueryPageSettings); printDocument.PrinterSettings.Copies = 1; printDocument.PrintController = spController; m_iPageNumber = 0; printDocument.DocumentName = cardMemberNameTextBox.Text; // Calling this method starts the printing process for this document printDocument.Print(); //PrinterSettings printerSettings = new PrinterSettings(); //printerSettings.GetHdevmode(); } // End PrintCard
private void printer() { string file = "Result Sheet " + DateTime.Now.ToString("_d_M_yyyy_hh_mm_ss"); string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); PrintDocument doc = new PrintDocument() { PrinterSettings = new PrinterSettings() { PrinterName = "Microsoft Print to PDF", PrintToFile = true, PrintFileName = Path.Combine(directory, file + ".pdf"), } }; PrintController printController = new StandardPrintController(); doc.PrintController = printController; doc.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); doc.Print(); }
private void btn_Invoice_Print_Click(object sender, EventArgs e) { // Tulostaa laskun // Tulostuksen koko: 794 x 1123 = A4 = 96 DPI. (Koko ulkoasusta.) PrintDocument to_print = new PrintDocument(); to_print.PrintPage += this.Print_document; PrintDialog dlgSettings = new PrintDialog(); dlgSettings.Document = to_print; if (dlgSettings.ShowDialog() == DialogResult.OK) { PrintController printController = new StandardPrintController(); to_print.PrintController = printController; // Muutetaan marginaalien kooksi 0. to_print.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); to_print.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); to_print.Print(); } }
private void printed() { string file = "Transaction" + DateTime.Now.ToString("_d_M_yyyy_hh_mm_ss"); string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); PrintDocument doc = new PrintDocument() { PrinterSettings = new PrinterSettings() { PrinterName = Properties.Settings.Default.printername, PrintToFile = true, PrintFileName = Path.Combine(directory, file + ".pdf"), } }; PrintController printController = new StandardPrintController(); doc.PrintController = printController; doc.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); doc.Print(); }
public void m_mthPrint(string printerName) { PrintController printController = new StandardPrintController(); this.m_printDoc.PrintController = printController; try { if (this.dsReport != null) { this.dsReport.Print(false); if (this.m_objPrintInfo != null) { string text = this.m_objPrintInfo.m_dtbBaseInfo.Rows[0]["application_id_chr"].ToString().Trim(); if (!string.IsNullOrEmpty(text)) { long num = this.m_mthWriteReportPrintState(text); } } } else { if (!string.IsNullOrEmpty(printerName)) { this.m_printDoc.PrinterSettings.PrinterName = printerName; } //this.m_printDlg = new PrintDialog(); //this.m_printDlg.Document = this.m_printDoc; //DialogResult dialogResult = this.m_printDlg.ShowDialog(); //if (dialogResult == DialogResult.OK) //{ this.m_printDoc.Print(); //} } } catch (Exception e) { //MessageBox.Show(e.ToString()); ExceptionLog.OutPutException("m_mthPrint-->" + e); } }
public void PrintQRTicket(Bitmap imgPrint, string dt, string type, string from, string to, string count, string price, string no)//, TicketGrid ticketGrid) { try { lineY = 2; printList = new List <PrintObject>(); string headerAddress = "Images\\kmlr_QR_logo.png"; Image img = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + headerAddress); System.Drawing.Bitmap logo = new System.Drawing.Bitmap(img); logo = new System.Drawing.Bitmap(logo, new System.Drawing.Size(180, 40)); AddLogoImage(logo); System.Drawing.Bitmap qrimg = new System.Drawing.Bitmap(imgPrint); qrimg = new System.Drawing.Bitmap(qrimg, new System.Drawing.Size(100, 100)); AddImage(qrimg); AddTextAfterImage("Date/Time", dt, 80); AddText("Type", type, 80); AddText("From", from, 80); AddText("To", to, 80); AddText("Price", price, 80); AddText("Ticket No", no, 80); AddText("Fare Mode", "Normal", 80); AddTextFar("------------------------------------------------------------------------------"); AddTextFar("Kochi1 card holder saved Rs"); AddTextFar("on this trip.Get your card now!!"); AddTextBold("Please retain till the end of journey!"); AddTextFar("------------------------------------------------------------------------------"); PrintDocument Document = new PrintDocument(); PrintController printController = new StandardPrintController(); Document.PrintController = printController; Document.PrintPage += new PrintPageEventHandler(printDocumentPrintPage); Document.PrinterSettings.PrinterName = PrinterName; Document.Print(); } catch (Exception ex) { log.Error("Error CustomKPM150HPrinter -> PrintQRTicket() : " + ex.ToString()); } }
public void print() { try { PrintDocument print = new PrintDocument(); int height = GetHight(); print.PrintPage += print_printpage; print.DefaultPageSettings.PaperSize = new PaperSize("printer", 1000, height); // print.DefaultPageSettings.PaperSize = new PaperSize("printer", 1000, 2000); print.PrinterSettings.PrinterName = Appsetting.print_name; PrintController printController = new StandardPrintController(); print.PrintController = printController; print.Print(); } catch (Exception ex) { throw new Exception("请检查打印机设置。"); } }
private void 取打印图_Click(object sender, EventArgs e) { PreviewPrintController previewController = new PreviewPrintController(); // previewController.UseAntiAlias = true; printDocument.PrintController = previewController;//赋值后,为打印预览模式,printDocument.Print() 不执行打印操作,执行预览操作 printDocument.Print(); PreviewPageInfo[] pageInfo = previewController.GetPreviewPageInfo(); if (pageInfo != null && pageInfo.Length > 0) { Image image = pageInfo[0].Image; Size s = pageInfo[0].PhysicalSize; Bitmap bitmap = new Bitmap(image, 620, s.Height); this.pictureBox1.BackColor = Color.White; this.pictureBox1.Image = (Image)bitmap; } StandardPrintController printController = new StandardPrintController(); printDocument.PrintController = printController; }
/// <summary> /// 打印预处理 /// </summary> private void Print() { PrintDocument printDoc = new PrintDocument(); string printerName = printDoc.PrinterSettings.PrinterName; if (m_streams == null || m_streams.Count == 0) { return; } printDoc.PrinterSettings.PrinterName = printerName; if (!printDoc.PrinterSettings.IsValid) { string msg = String.Format("Can't find printer \"{0}\".", printerName); throw new Exception(msg); } printDoc.PrintPage += new PrintPageEventHandler(PrintPage); StandardPrintController spc = new StandardPrintController(); printDoc.PrintController = spc; printDoc.Print(); }
private void Form1_Load(object sender, EventArgs e) { this.Hide(); PdfDocument doc = new PdfDocument(); doc.LoadFromFile(@"c:\Test\testpdf.pdf"); doc.PrintSettings.PrinterName = "Brother HL-L5100DN Series"; PrintDocument printdoc = new PrintDocument(); //printdoc.DocumentName = @"c:\Test\testpdf.pdf"; //var doc = printdoc.Load(@"c:\Test\testpdf.pdf"); //var printDoc = new PdfPrintDocument(doc); PrintController printController = new StandardPrintController(); printdoc.PrintController = printController; printdoc.PrinterSettings.PrinterName = "Brother HL-L5100DN Series"; //printdoc.PrinterSettings.PrinterName = "Brother HL-L5100DN Series"; printdoc.Print(); // Print PDF document this.Close(); }
public void PrintTestQRTicket(Bitmap imgPrint)//, TicketGrid ticketGrid) { try { lineY = 2; printList = new List <PrintObject>(); string headerAddress = "Images\\kmlr_QR_logo.png"; Image img = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + headerAddress); System.Drawing.Bitmap logo = new System.Drawing.Bitmap(img); logo = new System.Drawing.Bitmap(logo, new System.Drawing.Size(180, 40)); AddLogoImage(logo); System.Drawing.Bitmap qrimg = new System.Drawing.Bitmap(imgPrint); qrimg = new System.Drawing.Bitmap(qrimg, new System.Drawing.Size(100, 100)); AddImage(qrimg); AddTextAfterImage("Date/Time", Ticket.transactionDts.ToString("yyyy-MM-dd HH:mm"), 80); AddText("Type", Ticket.journeyType.ToString(), 80); AddText("From", Ticket.startStation.name, 80); AddText("To", Ticket.endStation.name, 80); AddText("Price", Convert.ToString(Ticket.totalPrice), 80); AddText("Ticket No", "000001111", 80); AddText("Fare Mode", "Normal", 80); AddTextFar("------------------------------------------------------------------------------"); AddTextBold(""); AddTextBold("Please retain till the end of journey!"); AddTextBold(""); AddTextFar("------------------------------------------------------------------------------"); PrintDocument Document = new PrintDocument(); PrintController printController = new StandardPrintController(); Document.PrintController = printController; Document.PrintPage += new PrintPageEventHandler(printDocumentPrintPage); Document.PrinterSettings.PrinterName = PrinterName; Document.Print(); } catch (Exception ex) { log.Error("Error CustomKPM150HPrinter -> PrintQRTicket() : " + ex.ToString()); } }
static public void Print(string printPath, string actualPrinter, short actualNumberOfCopies) { PrintDocument pd = new PrintDocument(); PrintController printController = new StandardPrintController(); pd.PrintController = printController; pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); pd.PrintPage += (sndr, args) => { System.Drawing.Image i = System.Drawing.Image.FromFile(printPath); i.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); System.Drawing.Rectangle m = args.MarginBounds; if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height) { m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width); } else { m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height); } pd.DefaultPageSettings.Landscape = m.Height > m.Width; m.Y = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Height - m.Height) / 2); m.X = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Width - m.Width) / 2); args.Graphics.DrawImage(i, m); }; pd.PrinterSettings.PrinterName = actualPrinter; Debug.WriteLine("actual number of copies: " + actualNumberOfCopies); // pd.PrinterSettings.Copies = actualNumberOfCopies; // pd.Print(); for (int i = 0; i < actualNumberOfCopies; i++) { pd.Print(); } }
public void PrintLable() { PrintDocument pd = new PrintDocument(); StandardPrintController controler = new StandardPrintController(); try { pd.PrintPage += new PrintPageEventHandler(this.PrintCustomLable); pd.PrintController = controler; pd.Print(); return; } catch (Exception err) { Console.WriteLine(err.Message); return; } finally { pd.Dispose(); } }
/// <summary> /// Call to print /// </summary> public virtual void Print(object sender, System.EventArgs e) { if (!this.printInProgress) { this.printDialog1.Document = this.document; DialogResult result = this.printDialog1.ShowDialog(); if (result == DialogResult.OK) { PrintController printController; printController = new StandardPrintController(); if (this.ShowStatusDialog) { this.document.PrintController = new PrintControllerWithStatusDialog( printController, "Please wait..."); } else { this.document.PrintController = printController; } onPrinting(); if (this.PrintInBackground) { // disable buttons or else the user could get into trouble! PrintInBackgroundDelegate d = new PrintInBackgroundDelegate( BeginBackgroundPrint); d.BeginInvoke(new AsyncCallback(PrintInBackgroundComplete), null); } else { this.printInProgress = true; this.document.Print(); this.printInProgress = false; onPrinted(); } } } }
private void PrintReceipt() { PrintDialog printDialog = new PrintDialog(); PrintDocument printDocument = new PrintDocument(); PrintController printController = new StandardPrintController(); printDocument.PrintController = printController; printDialog.Document = printDocument; printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); DialogResult result = printDialog.ShowDialog(); if (result == DialogResult.OK) { printDocument.Print(); } }
private static void PrintColor(Action <Boolean> callback, List <PhotoPath> photos, int nbPrints) { PrintDocument pd = new PrintDocument(); PrintController printController = new StandardPrintController(); pd.PrintController = printController; pd.PrintPage += (sender, args) => { System.Drawing.Image i = null; if (photos.Count == 1 && nbPrints == 1) { i = ResizeOnePictureAndAddLogo(photos[0].fileName); } else if (photos.Count == 1 && nbPrints == 4) { i = ResizeFourPicturesAndAddLogo(new List <PhotoPath> { photos[0], photos[0], photos[0], photos[0] }); } else if (photos.Count == 4) { i = ResizeFourPicturesAndAddLogo(photos); } if (i != null) { args.Graphics.DrawImage(i, 30, 20); } }; pd.EndPrint += (sender, args) => { callback(true); }; pd.PrinterSettings.PrinterName = "Canon SELPHY CP1300"; pd.Print(); }
/// <summary> /// 打印小票 /// </summary> public void PrintReceipt(bool isRefund) { isrefund = isRefund; //打印预览 PrintPreviewDialog ppd = new PrintPreviewDialog(); PrintDocument pd = new PrintDocument(); //设置边距 Margins margin = new Margins(20, 20, 20, 20); pd.DefaultPageSettings.Margins = margin; //纸张设置默认 PaperSize pageSize = new PaperSize("First custom size", getYc(58), 600); pd.DefaultPageSettings.PaperSize = pageSize; //打印事件设置 pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); //ppd.Document = pd; //ppd.ShowDialog(); try { PrintController printController = new StandardPrintController(); pd.PrintController = printController; pd.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); pd.PrintController.OnEndPrint(pd, new PrintEventArgs()); } }
public Tuple <bool, Exception> PrintTest(string printerName) { var tuple = new Tuple <bool, Exception>(true, null); #region 总写的 try { PrintController pc = new StandardPrintController(); var pd = new PrintDocument { PrintController = pc, DefaultPageSettings = { Margins = new Margins(0, 0, 0, 0) }, OriginAtMargins = true }; BasePrinter entity = new BasePrinter() { Title = "测试", DeskNo = "666", BeginAt = DateTime.Now, FinalMoney = Decimal.MaxValue, ExtraStr = "这是打印测试" }; pd.PrintPage += (s, e) => Pdoc_PrintPage(e, entity); pd.PrinterSettings.PrinterName = printerName; pd.Print(); } catch (Exception ex) { return(new Tuple <bool, Exception>(false, ex)); } #endregion return(tuple); }
static void PrintIron() { // Create a new PDF and print it IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf(); var pdf = IronPdf.PdfDocument.FromFile(@"c:\elektlabs\masa\doc\System_Manuals\MASA_OData.pdf"); //PdfDocument Pdf = Renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf"); // Send the PDF to the default printer to print // .Print(); using (var doc = pdf.GetPrintDocument()) { var controller = new StandardPrintController(); doc.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; doc.PrinterSettings.Copies = 1; doc.PrintController = controller; doc.Print(); } //For advanced silent real-world printing options, use PdfDocument.GetPrintDocument //Remember to add an assembly reference to System.Drawing.dll // System.Drawing.Printing.PrintDocument PrintDocYouCanWorkWith = pdf.GetPrintDocument(); }
public MainWindow() { InitializeComponent(); address = infile.ReadValue("CONFIG", "ADDRESS"); addressSave = infile.ReadValue("CONFIG", "ADDRESSSave"); string a = "020569780311932141656018027901188600178574445818676009179083681404611325017558988810910223024416059959220427736603679376380069730519525691492099"; var qrUrl = ConfigurationManager.AppSettings["QRURL"]; string res = RestClient.HttpPost(qrUrl, a); TicketInfo ticketInfo = JsonConvert.DeserializeObject <TicketInfo>(res); TicketGet ticketGet = new TicketGet(); ticketGet.trainDate = ticketInfo.ticket.trainDate; ticketGet.trainCodeAt = ticketInfo.ticket.trainCodeAt; ticketGet.coachNo = ticketInfo.ticket.coachNo; ticketGet.seatNo = ticketInfo.ticket.seatNo; ticketGet.seatType = ticketInfo.ticket.seatType; DataTable aa = SQLhelp.GetInfo(ticketGet); List <DJ60_change_seat_log> listdj = TableToList.ToDataList <DJ60_change_seat_log>(aa); dayinxieru(listdj); streamToPrint = new FileStream(@address, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); // 创建一个PrintDialog的实例。 PrintDialog PrintDialog1 = new PrintDialog(); // 把PrintDialog的Document属性设为上面配置好的PrintDocument的实例 streamToPrint.Close(); PrintDocument p = new PrintDocument(); //隐藏 对话框 PrintController printController = new StandardPrintController(); p.PrintController = printController; //创建打印画布 p.PrintPage += new PrintPageEventHandler(docToPrint_PrintPage); p.Print(); }
static void Main(string[] args) { var handle = GetConsoleWindow(); //hides cosole window // ShowWindow(handle, SW_HIDE); String strConnString = "Data Source=192.168.1.2;Initial Catalog=WMS;User ID=bodek;"; //multiple connections because each reader needs it's own connection SqlConnection conn = new SqlConnection(strConnString); SqlConnection conn2 = new SqlConnection(strConnString); SqlConnection conn3 = new SqlConnection(strConnString); SqlDataReader rdr = null; try { //gets a new QC Alert string sql = "select top 1 AI._rid_, AI.inv_trace, AI.inv_trace_old, AI.user_id, AI.owner_id, AI.product_id, AI.location_id, AI.Transaction_time, OS.Carrier_id " + " from audit_inventory AI, Outbound_shipments os " + " where trantype = 'QC' and subtype = 'AUDIT' and AI.inv_trace=OS.Shipment_id " + " and location_id is not null and exporttime_sys3 is null "; // Open the connection conn.Open(); conn2.Open(); conn3.Open(); SqlCommand cmd = new SqlCommand(sql, conn); rdr = cmd.ExecuteReader(); string Pickticket = ""; string msg = ""; string header_msg = ""; string RID = ""; string QCType = ""; while (rdr.Read()) { SqlDataReader Reader = null; SqlDataReader SDReader = null; string Auditsql; string ShortDescsql; string ShortDesc = ""; if (Pickticket != (rdr["inv_trace"].ToString() + rdr["inv_trace_old"].ToString())) { header_msg = "\n **************************\n"; header_msg += " *** QC Pick Required ***\n"; header_msg += " Origional Pick Ticket: " + rdr["inv_trace"] + rdr["inv_trace_old"]; header_msg += "\n CarrierID: " + rdr["carrier_id"]; header_msg += "\n QC User ID: " + rdr["user_id"]; header_msg += "\n Picker ID: " + rdr["owner_id"] + '\n'; } Pickticket = (rdr["inv_trace"].ToString() + rdr["inv_trace_old"].ToString()); Auditsql = "select product_id, ISNULL(defect_id,'UNKNOWN') as QC_CODE,"; Auditsql += " ISNULL(defect_id_old,'0') as QUANTITY "; Auditsql += " from audit_inventory_detail WITH (NOLOCK)"; Auditsql += " Where audit_inventory_rid = " + rdr["_rid_"]; SqlCommand Command = new SqlCommand(Auditsql, conn2); Reader = Command.ExecuteReader(); while (Reader.Read()) { ShortDescsql = "select short_description from product_master WITH (NOLOCK)"; ShortDescsql += " where product_id = '" + rdr["product_id"] + "'"; SqlCommand SDCommand = new SqlCommand(ShortDescsql, conn3); SDReader = SDCommand.ExecuteReader(); while (SDReader.Read()) { ShortDesc = SDReader["short_description"].ToString(); } SDReader.Close(); if (header_msg.Length > 0) { msg += header_msg; header_msg = ""; } msg += "\n * * * * * * * * * * * * \n"; msg += "\n Error Time : " + rdr["transaction_time"]; msg += "\n Product ID: " + rdr["product_id"]; msg += "\n Description: " + ShortDesc; msg += "\n Location ID: " + rdr["location_id"]; msg += "\n QC Code: " + Reader["QC_CODE"]; msg += "\n Quantity: " + Reader["Quantity"] + '\n'; QCType = Reader["QC_CODE"].ToString(); } if (RID.Length == 0) { RID = rdr["_rid_"].ToString(); } else { RID += ',' + rdr["_rid_"].ToString(); } Console.WriteLine(msg); Reader.Close(); PrintDocument p = new PrintDocument(); PrintController Controler = new StandardPrintController(); //designates a printer p.PrinterSettings.PrinterName = "P16"; //will hide the printing dialoge box p.PrintController = Controler; p.PrintPage += delegate(object sender1, PrintPageEventArgs e1) { e1.Graphics.DrawString(msg, new Font("Times New Roman", 25), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); }; try { if (QCType != "PLS") { p.Print(); } } catch (Exception ex) { throw new Exception(ex.Message); // Console.ReadLine(); } } updateAuditInventory(RID); rdr.Close(); // Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.Message); // Console.ReadLine(); } finally { if (conn != null) { conn.Close(); } if (conn2 != null) { conn2.Close(); } if (conn3 != null) { conn3.Close(); } } }
public void PrintAsFitonPaperSize(string FileName, bool isAutoPaperOrientation = true) { try { if (string.IsNullOrWhiteSpace(FileName)) { return; // Prevents execution of below statements if filename is not selected. } PrintDocument pd = new PrintDocument(); pd.DocumentName = "Xmaru"; //Disable the printing document pop-up dialog shown during printing. PrintController printController = new StandardPrintController(); pd.PrintController = printController; if (!pd.PrinterSettings.IsValid) { throw new Exception("PrinterSetting is not valid"); } if (!pd.PrinterSettings.IsDefaultPrinter) { throw new Exception("Default printer is not valid"); } //For testing only: Hardcoded set paper size to particular paper. //pd.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("Custom 6x4", 720, 478); //pd.DefaultPageSettings.PaperSize = new PaperSize("Custom 6x4", 720, 478); pd.DefaultPageSettings.Margins = new Margins(10, 10, 10, 10); pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(10, 10, 10, 10); System.Drawing.Image image = System.Drawing.Image.FromFile(FileName); bool isLandscapeImage = image.Width > image.Height; bool isLandscapeConfig = pd.DefaultPageSettings.Landscape; if (isAutoPaperOrientation) { if (isLandscapeImage != isLandscapeConfig) { pd.DefaultPageSettings.Landscape = isLandscapeImage; } } pd.PrintPage += (sender, args) => { //Adjust the size of the image to the page to print the full image without loosing any part of the image. System.Drawing.Rectangle m = args.MarginBounds; //Logic below maintains Aspect Ratio. if ((double)image.Width / (double)image.Height > (double)m.Width / (double)m.Height) // image is wider { m.Height = (int)((double)image.Height / (double)image.Width * (double)m.Width); } else { m.Width = (int)((double)image.Width / (double)image.Height * (double)m.Height); } m.Y = (int)((((System.Drawing.Printing.PrintDocument)(sender)).DefaultPageSettings.Bounds.Height - m.Height) / 2); m.X = (int)((((System.Drawing.Printing.PrintDocument)(sender)).DefaultPageSettings.Bounds.Width - m.Width) / 2); args.Graphics.DrawImage(image, m); }; pd.Print(); } catch (Exception ex) { } finally { } }
private void Btn_Click(object sender, EventArgs e) { Graphics graphics = Graphics.FromImage(image); Pen pen = new Pen(Color.Blue, 2); //横线 graphics.DrawLine(pen, 0, 1, 920, 1); graphics.DrawLine(pen, 0, 48, 920, 48); graphics.DrawLine(pen, 0, 96, 920, 96); graphics.DrawLine(pen, 0, 144, 920, 144); graphics.DrawLine(pen, 0, 168, 920, 168); graphics.DrawLine(pen, 0, 216, 920, 216); graphics.DrawLine(pen, 0, 264, 920, 264); graphics.DrawLine(pen, 0, 312, 920, 312); graphics.DrawLine(pen, 0, 360, 920, 360); graphics.DrawLine(pen, 0, 408, 920, 408); graphics.DrawLine(pen, 0, 456, 920, 456); graphics.DrawLine(pen, 0, 504, 920, 504); graphics.DrawLine(pen, 0, 552, 920, 552); graphics.DrawLine(pen, 0, 599, 920, 599); //竖线 graphics.DrawLine(pen, 0, 0, 0, 144); graphics.DrawLine(pen, 0, 168, 0, 600); graphics.DrawLine(pen, 210, 48, 210, 144); graphics.DrawLine(pen, 210, 168, 210, 600); graphics.DrawLine(pen, 410, 48, 410, 144); graphics.DrawLine(pen, 410, 168, 410, 600); graphics.DrawLine(pen, 685, 48, 685, 144); graphics.DrawLine(pen, 685, 168, 685, 600); graphics.DrawLine(pen, 920, 0, 920, 144); graphics.DrawLine(pen, 920, 168, 920, 600); Pen pen2 = new Pen(Color.Blue, 2); //粗体字 Font fontBold = new Font("微软雅黑", 17, FontStyle.Bold); Font fontR = new Font("微软雅黑", 16, FontStyle.Regular); Brush b = new SolidBrush(Color.Black); //标题位置 RectangleF rectangle4 = new RectangleF(0, 312, 210, 48); RectangleF rectangle5 = new RectangleF(410, 168, 210, 48); RectangleF rectangle6 = new RectangleF(0, 456, 210, 48); RectangleF rectangle7 = new RectangleF(402, 266, 402, 38); RectangleF rectangle8 = new RectangleF(0, 380, 402, 38); RectangleF rectangle9 = new RectangleF(402, 380, 402, 38); RectangleF rectangle1 = new RectangleF(0, 48, 210, 48); RectangleF rectangle2 = new RectangleF(0, 96, 210, 48); RectangleF rectangle3 = new RectangleF(410, 48, 210, 48); RectangleF studentID = new RectangleF(410, 96, 300, 48); RectangleF opening = new RectangleF(0, 168, 210, 48); RectangleF mar1 = new RectangleF(210, 168, 210, 48); RectangleF mar2 = new RectangleF(685, 168, 210, 48); RectangleF mar3 = new RectangleF(210, 312, 210, 48); RectangleF mar4 = new RectangleF(210, 456, 210, 48); RectangleF mar5 = new RectangleF(685, 456, 210, 48); RectangleF awarding = new RectangleF(410, 456, 300, 48); RectangleF rectangle10 = new RectangleF(0, 216, 210, 48); RectangleF rectangle11 = new RectangleF(410, 216, 210, 48); RectangleF rectangle12 = new RectangleF(0, 264, 210, 48); RectangleF rectangle13 = new RectangleF(410, 264, 210, 48); RectangleF rectangle14 = new RectangleF(410, 312, 210, 48); RectangleF rectangle15 = new RectangleF(0, 360, 210, 48); RectangleF rectangle16 = new RectangleF(410, 360, 210, 48); RectangleF rectangle17 = new RectangleF(0, 408, 210, 48); RectangleF rectangle18 = new RectangleF(410, 408, 210, 48); RectangleF rectangle19 = new RectangleF(0, 504, 210, 48); RectangleF rectangle20 = new RectangleF(410, 504, 210, 48); RectangleF rectangle21 = new RectangleF(0, 552, 210, 48); RectangleF rectangle22 = new RectangleF(410, 552, 210, 48); //灵活数据 //左边上三行矩形 RectangleF rectangle = new RectangleF(0, 0, 920, 48); RectangleF diyData1 = new RectangleF(210, 48, 200, 48); RectangleF diyData2 = new RectangleF(685, 48, 235, 48); RectangleF diyData3 = new RectangleF(210, 96, 200, 48); RectangleF diyData4 = new RectangleF(685, 96, 235, 48); RectangleF diyData5 = new RectangleF(210, 216, 200, 48); RectangleF diyData6 = new RectangleF(685, 216, 235, 48); RectangleF diyData7 = new RectangleF(210, 264, 200, 48); RectangleF diyData8 = new RectangleF(685, 264, 235, 48); RectangleF diyData9 = new RectangleF(685, 312, 235, 48); RectangleF diyData10 = new RectangleF(210, 360, 200, 48); RectangleF diyData11 = new RectangleF(685, 360, 235, 48); RectangleF diyData12 = new RectangleF(210, 408, 200, 48); RectangleF diyData13 = new RectangleF(685, 408, 235, 48); RectangleF diyData14 = new RectangleF(210, 504, 200, 48); RectangleF diyData15 = new RectangleF(685, 504, 235, 48); RectangleF diyData16 = new RectangleF(210, 552, 200, 48); RectangleF diyData17 = new RectangleF(685, 552, 235, 48); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; //固定粗体栏位 graphics.DrawString("Division", fontBold, b, rectangle1, sf); graphics.DrawString("Team ID", fontBold, b, rectangle2, sf); graphics.DrawString("Student ID", fontBold, b, rectangle3, sf); graphics.DrawString("Hotel Shuttle Bus Time", fontBold, b, studentID, sf); graphics.DrawString("Opening", fontBold, b, opening, sf); graphics.DrawString("Mar.16th", fontBold, b, mar1, sf); graphics.DrawString("Critical Thinking", fontBold, b, rectangle5, sf); graphics.DrawString("Mar.16th", fontBold, b, mar2, sf); graphics.DrawString("Qualifying Test", fontBold, b, rectangle4, sf); graphics.DrawString("Mar.16th", fontBold, b, mar3, sf); graphics.DrawString("Super Econ !", fontBold, b, rectangle6, sf); graphics.DrawString("Mar.16th", fontBold, b, mar4, sf); graphics.DrawString("Awarding & Quiz Bowl", fontBold, b, awarding, sf); graphics.DrawString("Mar.17th", fontBold, b, mar5, sf); //固定细体 graphics.DrawString("Entry Time", fontR, b, rectangle10, sf); graphics.DrawString("Entry Time", fontR, b, rectangle11, sf); graphics.DrawString("Seat", fontR, b, rectangle12, sf); graphics.DrawString("Reading Time", fontR, b, rectangle13, sf); graphics.DrawString("Discussion Time", fontR, b, rectangle14, sf); graphics.DrawString("Entry Time", fontR, b, rectangle15, sf); graphics.DrawString("Presentation Time", fontR, b, rectangle16, sf); graphics.DrawString("Seat", fontR, b, rectangle17, sf); graphics.DrawString("Slot", fontR, b, rectangle18, sf); graphics.DrawString("Entry Time", fontR, b, rectangle19, sf); graphics.DrawString("Entry Time", fontR, b, rectangle20, sf); graphics.DrawString("Table", fontR, b, rectangle21, sf); graphics.DrawString("Seat", fontR, b, rectangle22, sf); Brush diyDataB = new SolidBrush(Color.Red); //需要匹配的栏位数据 /* * graphics.DrawString("Gil Zhang", font, diyDataB, rectangle, sf); * graphics.DrawString("Division", font, diyDataB, diyData1, sf); * graphics.DrawString("Team ID", font, diyDataB, diyData2, sf); * graphics.DrawString("Candidate ID", font, diyDataB, diyData3, sf); * graphics.DrawString("Time", font, diyDataB, diyData4, sf); * graphics.DrawString("Time", font, diyDataB, diyData5, sf); * graphics.DrawString("Seat", font, diyDataB, diyData6, sf); * graphics.DrawString("Seat", font, diyDataB, diyData7, sf); * graphics.DrawString("Time", font, diyDataB, diyData8, sf); * graphics.DrawString("Time", font, diyDataB, diyData9, sf); * graphics.DrawString("Table", font, diyDataB, diyData10, sf); * graphics.DrawString("Table", font, diyDataB, diyData11, sf); * graphics.DrawString("Workshop 1 Time", font, diyDataB, diyData12, sf); * graphics.DrawString("Time", font, diyDataB, diyData13, sf); * graphics.DrawString("Workshop 2 Time", font, diyDataB, diyData14, sf); * graphics.DrawString("Room", font, diyDataB, diyData15, sf); * //graphics.DrawString("测试数据", font, b, rectangle, sf); */ StringFormat sfC = new StringFormat(); sfC.Alignment = StringAlignment.Center; sfC.LineAlignment = StringAlignment.Center; string str = textBox1.Text; string[] vs = str.Split('|'); if (vs != null && vs.Length > 15) { graphics.DrawString(vs[0], fontR, diyDataB, rectangle, sfC); graphics.DrawString(vs[1], fontR, diyDataB, diyData1, sf); graphics.DrawString(vs[2], fontR, diyDataB, diyData2, sf); graphics.DrawString(vs[3], fontR, diyDataB, diyData3, sf); graphics.DrawString(vs[4], fontR, diyDataB, diyData4, sf); graphics.DrawString(vs[5], fontR, diyDataB, diyData5, sf); graphics.DrawString(vs[6], fontR, diyDataB, diyData6, sf); graphics.DrawString(vs[7], fontR, diyDataB, diyData7, sf); graphics.DrawString(vs[8], fontR, diyDataB, diyData8, sf); graphics.DrawString(vs[9], fontR, diyDataB, diyData9, sf); graphics.DrawString(vs[10], fontR, diyDataB, diyData10, sf); graphics.DrawString(vs[11], fontR, diyDataB, diyData11, sf); graphics.DrawString(vs[12], fontR, diyDataB, diyData12, sf); graphics.DrawString(vs[13], fontR, diyDataB, diyData13, sf); graphics.DrawString(vs[14], fontR, diyDataB, diyData14, sf); graphics.DrawString(vs[15], fontR, diyDataB, diyData15, sf); graphics.DrawString(vs[16], fontR, diyDataB, diyData16, sf); graphics.DrawString(vs[17], fontR, diyDataB, diyData17, sf); } graphics.Flush(); pen.Dispose(); pen2.Dispose(); fontR.Dispose(); fontBold.Dispose(); b.Dispose(); _printWidth = (double)92 / 25.40000; _printHeight = (double)59 / 25.40000; //graphics.DrawString("测试数据", font, b, rectangle, sf); PrintDocument printDocument = new PrintDocument(); PrintController printController = new StandardPrintController();//禁止"打印中"弹窗 printDocument.PrintController = printController; printDocument.PrintPage += PrintDocument_PrintPage; printDocument.Print(); pictureBoxRet.Image = image; }
public void test() { StandardPrintController std = new StandardPrintController(); }
public void Print(BO23SlipModel bo23) { _printInfo = bo23; string logText; try { if (!_objAPI.IsValid) { if (_objAPI.OpenMonPrinter(OpenType.TYPE_PRINTER, this.PRINTER_NAME) != ErrorCode.SUCCESS) { logText = "ผิดพลาด! ไม่สามารถเปิดตัวติดตามสถานะเครื่องพิมพ์ได้" + Environment.NewLine + printStatus.ToString(); log.AppendText(logText); System.Diagnostics.Debug.WriteLine(logText); return; } } isFinish = false; cancelErr = false; isTimeout = false; if (_objAPI.SetStatusBack() == ErrorCode.SUCCESS) { using (PrintDocument pdPrint = new PrintDocument()) { PrintController pc = new StandardPrintController(); pdPrint.PrintController = pc; pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage); pdPrint.PrinterSettings.PrinterName = this.PRINTER_NAME; if (pdPrint.PrinterSettings.IsValid) { pdPrint.DocumentName = "SLIP"; pdPrint.Print(); Stopwatch sw = new Stopwatch(); sw.Start(); do { if (isFinish) { _objAPI.CancelStatusBack(); } if (sw.ElapsedMilliseconds > 5000) { isFinish = true; isTimeout = true; } } while (!isFinish); sw.Stop(); if (isTimeout) { ForceResetPrinter(); } else { LogStatusMessage(); //if ((printStatus & ASB.ASB_PAPER_END) == ASB.ASB_PAPER_END) CancelPrintJob(); if (cancelErr) { _objAPI.CancelError(); } } } else { logText = "ผิดพลาด! เครื่องพิมพ์ไม่เชื่อมต่อ"; log.AppendText(logText); System.Diagnostics.Debug.WriteLine(logText); } } } else { logText = "ผิดพลาด! ไม่สามารถตั้งฟังก์ชันเรียกกลับสถานะเครื่องพิมพ์"; log.AppendText(logText); System.Diagnostics.Debug.WriteLine(logText); } } catch (Exception ex) { logText = ex.Message; log.AppendText(logText); System.Diagnostics.Debug.WriteLine(logText); } }
/// <summary> /// 打印 /// </summary> /// <param name="seq">序号,用于区分回调</param> /// <param name="printerName">打印机,如果不指定,则使用画面上的打印机</param> /// <param name="imageList">待打印图片列表</param> protected void printImage(string seq, string printer, List <KeyValuePair <string, string> > imageList) { // 根据名称获取对应打印机 PrinterSetting printerSetting = null; foreach (PrinterSetting ps in PrintSetting.Printers) { if (String.IsNullOrEmpty(printer) && ps.IsDefault) { printerSetting = ps; break; } if (ps.ID == printer || ps.Printer == printer) { printerSetting = ps; break; } } if (printerSetting == null) { // 未找到指定打印机 return; } // 设置打印时不再弹打印进度弹窗 PrintController printController = new StandardPrintController(); PrintDocument printDoc = new PrintDocument(); printDoc.DefaultPageSettings.Landscape = printerSetting.Landscape; printDoc.PrinterSettings.PrinterName = printerSetting.Printer; printDoc.PrinterSettings.Copies = 1; //if (!String.IsNullOrEmpty(seq)) { // printDoc.PrinterSettings.PrintFileName = seq; //} // printDoc.OriginAtMargins = true; printDoc.PrintController = printController; // 开始打印事件 printDoc.BeginPrint += (object sender, PrintEventArgs e) => { Logger.InfoLog("print begin" + seq); WsResponse <string> br = new WsResponse <string>(); br.Seq = seq; br.Data = "begin"; Send(JsonConvert.SerializeObject(br)); }; // 结束打印事件 printDoc.EndPrint += (object sender, PrintEventArgs e) => { Logger.InfoLog("print end " + seq); WsResponse <string> er = new WsResponse <string>(); er.Seq = seq; er.Data = "end"; Send(JsonConvert.SerializeObject(er)); }; int page = 1; // 打印,每一页执行一次该事件 printDoc.PrintPage += (object sender, PrintPageEventArgs e) => { // inch int x = toInchX100(printerSetting.MarginLeft); int y = toInchX100(printerSetting.MarginTop); // inch int xr = toInchX100(printerSetting.MarginRight); int yb = toInchX100(printerSetting.MarginBottom); int w = 300, h = 551; switch (printerSetting.Paper) { case "1": { w = 300; // 285; // 300* 0.95 h = 511; // 485; // 511 * 0.95 break; } case "2": { w = toInchX100(100); h = toInchX100(180); break; } case "3": default: { w = toInchX100(100); h = toInchX100(180); } break; } e.PageSettings.Margins.Left = 0; e.PageSettings.Margins.Top = 0; e.PageSettings.Margins.Bottom = 0; e.PageSettings.Margins.Right = 0; e.PageSettings.PaperSize = new PaperSize("自定义", w, h); //foreach (KeyValuePair<string, string> image in imageList) //{ KeyValuePair <string, string> image = imageList[page - 1]; // Image i = Image.FromFile(image); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(image.Value); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) //获得响应) { if (response.StatusCode != HttpStatusCode.OK) { WsResponse <KeyValuePair <string, string> > rerr = new WsResponse <KeyValuePair <string, string> >(); rerr.Seq = seq; rerr.Code = "NET_ERR"; rerr.Data = new KeyValuePair <string, string>(image.Key, "error:" + response.StatusCode); string msgerr = JsonConvert.SerializeObject(rerr); Send(msgerr); } else { using (Stream stream = response.GetResponseStream()) { Image img = Image.FromStream(stream);///实例化,得到img // Conole.wrimg.Width img.Height Console.WriteLine(img.Width + "x" + img.Height); Console.WriteLine(e.PageSettings.HardMarginX + "x" + e.PageSettings.HardMarginY); if (printerSetting.AutoSize) { // e.MarginBounds e.MarginBounds.Offset(0, 0); //Console.WriteLine(e.MarginBounds); //Rectangle rect = new Rectangle(x, y, w - x - xr, h - y - yb); //e.Graphics.DrawImage(img, rect); e.Graphics.DrawImage(img, e.MarginBounds); } else { e.MarginBounds.Offset(0, 0); e.Graphics.DrawImage(img, e.PageSettings.HardMarginX + x, e.PageSettings.HardMarginY + y, w, h); } } Logger.InfoLog("print printed" + image.Key + " data:" + image.Value); WsResponse <KeyValuePair <string, string> > rimage = new WsResponse <KeyValuePair <string, string> >(); rimage.Seq = seq; rimage.Data = new KeyValuePair <string, string>(image.Key, "printed"); string msgImage = JsonConvert.SerializeObject(rimage); Send(msgImage); } } //} if (page < imageList.Count) { // 表示还有下一页, e.HasMorePages = true; } else { e.HasMorePages = false; } page++; }; printDoc.Print(); WsResponse <string> r = new WsResponse <string>(); r.Seq = seq; r.Data = "printed"; string msg = JsonConvert.SerializeObject(r); Send(msg); }
static void Main(string[] args) { DebugLog log = new DebugLog(); String strConnString = "Data Source=192.168.5.1;Initial Catalog=WMS;User ID=bodek;"; //multiple connections because each reader needs it's own connection SqlConnection conn = new SqlConnection(strConnString); SqlConnection conn2 = new SqlConnection(strConnString); SqlConnection conn3 = new SqlConnection(strConnString); SqlConnection conn4 = new SqlConnection(strConnString); SqlDataReader rdr = null; log.Write("Test"); try { //gets a new QC Alert string sql = "select distinct top 1 * from outbound_shipments where customer_id='101210' and trailer_number is null and (Status = 'P'or status ='C' or Status ='I' or Status ='Z') "; // Open the connection conn.Open(); conn2.Open(); conn3.Open(); SqlCommand cmd = new SqlCommand(sql, conn); rdr = cmd.ExecuteReader(); string Pickticket = ""; string msg = ""; string header_msg = ""; string RID = ""; string QCType = ""; while (rdr.Read()) { Utility UT = new Utility(); string shipmentID = rdr["SHIPMENT_ID"].ToString(); string printer = rdr["Trailer_seal_1"].ToString(); string copies = rdr["Trailer_seal_2"].ToString(); // RID = rdr["_RID_"].ToString(); int count = UT.GetNumberOfCartons(shipmentID); //string sql2 = "select shipment_id from outbound_shipment_deatils where shipment_id='" + rdr["SHIPMENT_ID"].ToString() + "'"; //conn4.Open(); //SqlCommand cmd2 = new SqlCommand(sql2, conn4); //SqlDataReader rdr2 = cmd.ExecuteReader(); //while (rdr2.Read()) //{ // count++; //} //rdr2.Close(); SqlDataReader Reader = null; SqlDataReader SDReader = null; string Auditsql; string ShortDescsql; string ShortDesc = ""; Pen blackPen = new Pen(Color.Black, 3); // Create location and size of rectangle. int x = 0; int y = 0; int width = 200; int height = 200; // Draw rectangle to screen. System.Drawing.Printing.PrintPageEventArgs e; msg = "\n"; msg += "ORDER #: " + shipmentID; msg += "\nPO #: " + UT.GetPurchaseOrder(shipmentID) + "\n"; msg += "# of Cartons: ___/" + count + "\n"; msg += "asn #: ____________\n"; if (count < 160) { msg += "partial cases: ☑\n"; msg += "full cases: ☐\n "; } else { msg += "partial cases: ☐\n "; msg += "full cases: ☑\n "; } int max = 0; if (copies == "" || copies == null) { max = 15; } else { max = Convert.ToInt16(copies); } int cnt = 0; PrintDocument p = new PrintDocument(); PrintController Controler = new StandardPrintController(); //designates a printer if (printer == "" || printer == null) { p.PrinterSettings.PrinterName = "PACKSLIP8"; } else { p.PrinterSettings.PrinterName = printer; } p.DefaultPageSettings.Landscape = true; //will hide the printing dialoge box p.PrintController = Controler; p.PrintPage += delegate(object sender1, PrintPageEventArgs e1) { e1.Graphics.DrawString(msg, new Font("Times New Roman", 55), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); //e1.Graphics.DrawString(msg1, new Font("Times New Roman", 50), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); }; try { while (cnt < max) { cnt++; //if(QCType!="PLS") p.Print(); } } catch (Exception ex) { throw new Exception(ex.Message); } updateAuditInventory(shipmentID); log.Write(" SHipment: " + shipmentID + " Printed"); } rdr.Close(); // Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.Message); // Console.ReadLine(); } finally { if (conn != null) { conn.Close(); } if (conn2 != null) { conn2.Close(); } if (conn3 != null) { conn3.Close(); } if (conn4 != null) { conn3.Close(); } } }
public void theoutTicket(object source, System.Timers.ElapsedEventArgs e) { tTicket.Stop(); tTicket.Close(); try { int flag = Dll_Camera.StartDevice();//启动设备(1设备启动成功) if (flag != 1) { tTicket.Start(); return; } Dll_Camera.SetBeep(true); //蜂鸣开启 int flagg = Dll_Camera.GetDevice(); //查找设备(1设备查找成功) if (flagg != 1) { Dll_Camera.ReleaseLostDevice(); tTicket.Start(); return; } //设置qr Dll_Camera.setQRable(true); //QR引擎开启 Dll_Camera.SetBeepTime(100); //蜂鸣时间 Dll_Camera.SetDecodeTime(200); int Length = 1024; StringBuilder tempStr = new StringBuilder(Length); Dll_Camera.setQRable(false);//为防止重复信息误读 关闭解码 Dll_Camera.GetDecodeString(tempStr, out Length); var result = ""; if (Length > 0) { result = tempStr.ToString(); var qrUrl = ConfigurationManager.AppSettings["QRURL"]; string res = RestClient.HttpPost(qrUrl, result); TicketInfo ticketInfo = JsonConvert.DeserializeObject <TicketInfo>(res); if (ticketInfo.status == 1) { TicketGet ticketGet = new TicketGet(); ticketGet.trainDate = ticketInfo.ticket.trainDate; ticketGet.trainCodeAt = ticketInfo.ticket.trainCodeAt; ticketGet.coachNo = ticketInfo.ticket.coachNo; ticketGet.seatNo = ticketInfo.ticket.seatNo; ticketGet.seatType = ticketInfo.ticket.seatType; DataTable aa = SQLhelp.GetInfo(ticketGet); List <DJ60_change_seat_log> listdj = TableToList.ToDataList <DJ60_change_seat_log>(aa); dayinxieru(listdj); streamToPrint = new FileStream(@address, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); // 创建一个PrintDialog的实例。 PrintDialog PrintDialog1 = new PrintDialog(); // 把PrintDialog的Document属性设为上面配置好的PrintDocument的实例 streamToPrint.Close(); PrintDocument p = new PrintDocument(); //隐藏 对话框 PrintController printController = new StandardPrintController(); p.PrintController = printController; //创建打印画布 p.PrintPage += new PrintPageEventHandler(docToPrint_PrintPage); p.Print(); //DoPrint(ticketInfo.ticket); } else {//根据二维码信息获取旅客信息失败 return; } this.Dispatcher.Invoke(new Action(() => { //dayinxieru(result); //streamToPrint = new FileStream(@address, FileMode.OpenOrCreate, FileAccess.ReadWrite, // FileShare.None); //// 创建一个PrintDialog的实例。 //PrintDialog PrintDialog1 = new PrintDialog(); //// 把PrintDialog的Document属性设为上面配置好的PrintDocument的实例 //streamToPrint.Close(); //PrintDocument p = new PrintDocument(); ////隐藏 对话框 //PrintController printController = new StandardPrintController(); //p.PrintController = printController; ////创建打印画布 //p.PrintPage += new PrintPageEventHandler(docToPrint_PrintPage); //p.Print(); frameMain.NavigationService.GoBack(); this.back.Visibility = Visibility.Hidden; this.topTitle.Content = "席位置换自助终端"; })); } else { tTicket.Start(); return; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void doPrint() { PrintDocument pd = new PrintDocument { PrinterSettings = { PrinterName = ConfigHelper.ZebraPrinter } }; StandardPrintController pc = new StandardPrintController(); pd.PrintController = pc; pd.DefaultPageSettings.Margins = new Margins(5, 0, 0, 0); pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(5, 0, 0, 0); if (pd.PrinterSettings.IsValid == false) { throw new Exception(pd.PrinterSettings.PrinterName); } // set the document name to a guid pd.DocumentName = Guid.NewGuid().ToString(); // call the print page event to put the xml document information on the pass pd.PrintPage += (sndr, args) => { Font lineFont = new Font("Arial", 8); float lineHeight = lineFont.GetHeight(args.Graphics); Font lineFontBold = new Font("Arial", 9, FontStyle.Bold); float lineBoldHeight = lineFontBold.GetHeight(args.Graphics); Font headerFont = new Font("Arial", 11, FontStyle.Bold); float headerHeight = headerFont.GetHeight(args.Graphics); Font footerFont = new Font("Arial", 7); float footerHeight = footerFont.GetHeight(args.Graphics); float leftMargin = args.MarginBounds.Left; float topMargin = args.MarginBounds.Top; int height = args.PageSettings.PaperSize.Height; int width = args.PageSettings.PaperSize.Width; float yPos = 15; StringFormat sfRight = new StringFormat(); sfRight.Alignment = StringAlignment.Far; sfRight.LineAlignment = StringAlignment.Far; StringFormat sfLeft = new StringFormat(); sfLeft.Alignment = StringAlignment.Near; sfLeft.LineAlignment = StringAlignment.Near; args.Graphics.DrawString(string.Format("{0} {1}科 {2}床", this.txtName.Text, this.txtDepartment.Text.Replace("科", ""), this.txtNumber.Text.Replace("床", "")), headerFont, Brushes.Black, leftMargin, yPos, sfLeft); yPos += topMargin + headerHeight + 10; args.Graphics.DrawString(string.Format(" {0}Kcal / {1}ml X {2}{3}", this.txtKCal.Text, this.txtML.Text, this.quantity.Value, this.cbUnit.Text), lineFontBold, Brushes.Black, leftMargin, yPos, sfLeft); yPos = yPos + lineBoldHeight + 10; args.Graphics.DrawString("配制时间:" + this.dt.Value.ToString("yyyy-MM-dd HH:mm"), lineFont, Brushes.Black, leftMargin, yPos, sfLeft); yPos = yPos + lineHeight; args.Graphics.DrawString("冷藏保存 24小时", footerFont, Brushes.Black, leftMargin, yPos, sfLeft); yPos = yPos + lineHeight; args.Graphics.DrawString(" 仅供肠内营养治疗 严禁静脉输注", footerFont, Brushes.Black, leftMargin, yPos, sfLeft); yPos = yPos + lineHeight; args.Graphics.DrawString(" 交大二附院营养科 029-87679504", footerFont, Brushes.Black, leftMargin, yPos, sfLeft); args.HasMorePages = false; }; // set the portrait pd.DefaultPageSettings.Landscape = false; // print pd.Print(); pd.Dispose(); }
public JsonResult PrinttoPrinters(string PrintDate, int LocKy, int OrdKy) { String KOTReportPath = WebConfigurationManager.AppSettings["KOTReportPath"]; string states = "Fail"; List <string> Printers = new List <string>(); foreach (var printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { Printers.Add(printer.ToString()); //Its created for incase of find Printers list on this PC } try { string[] afdate = PrintDate.Split('/'); string Date = afdate.GetValue(0).ToString(); string ddlfmonth = afdate.GetValue(1).ToString(); string ddlfyear = afdate.GetValue(2).ToString(); string sDlydate = ddlfyear + "/" + ddlfmonth + "/" + Date; int UsrKy = HTNSession.UsrKy; int CKy = HTNSession.CKy; List <SplLocWithPrinter> list = new List <SplLocWithPrinter>(); list = apiOpr.PrintToLoc(HTNSession.Environment, CKy, OrdKy, UsrKy, sDlydate, LocKy); if (list.Count <= 0) { apiOpr.PrintLog_Insert(HTNSession.Environment, CKy, UsrKy, Convert.ToInt32(LocKy), OrdKy, "No record return from SP", sDlydate, states); } for (int i = 0; i < list.Count; i++) { if (list[i].PrinterNm == "error") { // Here Printer name is NULL } else { try { System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings(); printerSettings.PrinterName = list[i].PrinterIP; // +"\\" + list[i].PrinterNm; if (printerSettings.IsValid) { Telerik.Reporting.UriReportSource uriReportSource = new Telerik.Reporting.UriReportSource(); uriReportSource.Uri = AppDomain.CurrentDomain.BaseDirectory + KOTReportPath; uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrdKy", OrdKy)); uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("UsrKy", UsrKy)); uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("PrinterLoc", list[i].ProdLocCd)); uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("ProdLocKy", LocKy)); uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("DlryDt", sDlydate)); PrintController printController = new StandardPrintController(); ReportProcessor reportProcessor = new ReportProcessor(); reportProcessor.PrintController = printController; reportProcessor.PrintReport(uriReportSource, printerSettings); states = "Print Done"; } else { states = "It's Not Valid Printer"; } } catch (Exception ex) { states = "Exception"; } } apiOpr.PrintLog_Insert(HTNSession.Environment, CKy, UsrKy, Convert.ToInt32(LocKy), OrdKy, list[i].PrinterIP, sDlydate, states); } return(Json(states, JsonRequestBehavior.AllowGet)); } catch { return(Json(states, JsonRequestBehavior.AllowGet)); } }