在 C# 中将 ESC 命令发送到打印机 [英] Send ESC commands to a printer in C#

查看:31
本文介绍了在 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 命令发送到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆