Send ESC commands to a printer in C#(在 C# 中向打印机发送 ESC 命令)
问题描述
我的应用程序需要打印发票,然后从数据库中获取发票,在发票上插入一个大字符串中的信息(告诉行、列等),然后我准备好将字符串发送到打印机.
My application needs to print invoices, then a get the invoice from database, insert information on the invoice in a big string (telling the line, column, etc.) after this I have the string ready to be sent to a printer.
我的问题是:我需要在我的大字符串中放入一些 ESC/P 命令/字符
My problem is: I need to put some ESC/P commands/characters in my big string
我试图做这样的事情:
char formFeed = (char)12;
Convert.ToChar(12);
MyBigString.Insert(10, formFeed);
这样,第 10 行将执行 FormFeed,但这不起作用
Whith this, the line 10 will do a FormFeed, but this doesn't work
注意:我将 MybigString 一次性发送到打印机.
NOTE: I send the MybigString all at once to the printer.
为了让我的代码正常工作,我需要将数据逐行发送到打印机吗?
To make my code works, I need to send the data line by line to a printer?
感谢您的帮助.
PS:抱歉,对于我的英语,我是一名不会说英语的巴西开发人员(目前).
PS: Sorry, for my English, I'am a Brazilian developer which don't speak English (yet).
推荐答案
绕过打印机驱动程序并使用其本机命令语言直接控制打印机是受支持的方案.P/Invoke 在这个 KB 中有很好的解释文章.
Bypassing the printer driver and controlling the printer directly, using its native command language, is a supported scenario. The P/Invoke is explained well in this KB article.
确定要这样做吗?委婉地说,这种情况并不常见,通常只尝试使用低成本的销售点热敏打印机或矩阵打印机.如果您不喜欢 PrintDocument.PrintPage 的机制,没人喜欢,您可以考虑我在 这个线程.注意 FormFeed 方法.
Sure you want to do this? It is uncommon, to put it mildly, usually only attempted with low-cost Point-Of-Sale thermal or matrix printers. If you don't like the mechanics of PrintDocument.PrintPage, nobody does, you could consider my code in this thread. Note the FormFeed method.
这篇关于在 C# 中向打印机发送 ESC 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中向打印机发送 ESC 命令


- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01