问题描述
我的应用程序需要打印发票,然后从数据库中获取发票,在发票上插入一个大字符串中的信息(告诉行、列等),然后我准备好将字符串发送到打印机.
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 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!