所以,我需要从Windows窗体应用程序(c#,.net 4)打印到激光打印机,我发现了超级“有趣的”PrintDocument类,现在有代码可以工作,但是看起来像这样:
private void PrintCollate(vws.custom.production.IndiPackLabel ipl) { var pd = new PrintDocument(); pd.DocumentName = "Collate"; var printerSettings = new System.Drawing.Printing.PrinterSettings(); printerSettings.PrinterName = "HP LaserJet 4100"; pd.PrinterSettings = printerSettings; pd.PrinterSettings.copies = 1; _currCollate = ipl; pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); pd.Print(); _currCollate = null; } private static vws.custom.production.IndiPackLabel _currCollate; public void pd_PrintPage(Object sender,System.Drawing.Printing.PrintPageEventArgs e) { float linesPerPage = 0; //int count = 0; float leftMargin = 20; float topMargin = 20; float yPos = topMargin; var printFontnormal = new System.Drawing.Font("consolas",10); var printFontnormalBold = new System.Drawing.Font("consolas",10,FontStyle.Bold); float stdFontHeight = printFontnormal.GetHeight(e.Graphics); var printFontSmall = new System.Drawing.Font("consolas",8); float smallFontHeight = printFontSmall.GetHeight(e.Graphics); linesPerPage = e.MarginBounds.Height / stdFontHeight; e.Graphics.DrawString(("Order: " + _currCollate.OrderDescription).padright(91) + "ORD #:" + _currCollate.OrderNumber,printFontnormal,Brushes.Black,leftMargin,yPos); yPos += stdFontHeight; string customerInfo = (_currCollate.Customer.FirstName + " " + _currCollate.Customer.LastName).padright(90) + " BAG #" + _currCollate.BagNumber; e.Graphics.DrawString(customerInfo,yPos); yPos += stdFontHeight; yPos += stdFontHeight; string header = "ITEMNO".padright(20) + "ITEM NAME".padright(70) + "QTY".padright(3); e.Graphics.DrawString(header,printFontnormalBold,yPos); int itemTotal = 0; foreach (var item in _currCollate.OrderItems) { yPos += stdFontHeight; string itemLine = item.ItemNo.padright(20) + (item.ItemName + " " + item.OptionNames).padright(70) + item.Qty.ToString().padright(3); e.Graphics.DrawString(itemLine,yPos); if (item.Notes.Length > 0) { yPos += stdFontHeight; string notesLine = string.Empty.padright(20) + item.Notes; e.Graphics.DrawString(notesLine,yPos); } itemTotal += item.Qty; } yPos += stdFontHeight; string footer = "TOTAL ITEMS: ".padright(90) + itemTotal; e.Graphics.DrawString(footer,yPos); e.Graphics.DrawRectangle(new Pen(Color.Black,2),new Rectangle(20,600,700,500)); }
一定有更好的方法。 特别是当我必须在6个月内改变这一点,必须重新计算出来。
我正在使用Neodynamic的热敏标签SDK(http://www.neodynamic.com/ND/ProductsPage.aspx?tabid=107&prod=thermallabel)来打印Zebra打印机,并希望有一个类似的API来创build激光打印文档打印机。 我还需要将条形码打印添加到此打印文档中,因此,包含条形码function的任何工具都将更有帮助。
有什么build议么?
从Internet Explorer将原始EPL2打印到Zebra Thermal
当用户按下打印时运行脚本,而不是在脚本结束之前启动假脱机(linux,cups)
如何在控制台的单行显示倒计时?
在没有Windows打印对话框的情况下使用PHP(javascript)在本地打印页面
Windows打印处理器是否可以强制假脱机数据types
Python 3.2.2在Mac上打印函数语法错误,但不在Windows上
在Win32中显示“打印首选项”对话框
需要一种可以驱动两台打印机的快速编程语言
我想创build一个批处理脚本,将按照date修改的顺序打印文件夹中的所有文件
如果你需要在窗体上显示的窗体打印,我建议使用DrawToBitmap方法。 更多详细信息: 如何以编程方式获取.Net控件的屏幕截图 。 这种方法也适用于复合控件(例如整个表单)。
如果您需要更高级的打印功能,我会建议寻找一些.NET报表库(可能是其中之一: Report Viewer / Crystal Reports / sql server Reporting Services)。 这个虽然没有详细的指导,但我自己还没有使用过。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。