条码打印asp.net c# [英] barcode Printing asp.net c#

查看:67
本文介绍了条码打印asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string command =^ XA ^ FO10,10,^ AO,30,20 ^ FDFDTesting ^ FS ^ FO10,30 ^ BY3 ^ BCN,100,Y,N,N ^ FDTesting ^ FS ^ XZ;



//使用命令创建一个缓冲区

Byte [] buffer = new byte [command.Length];

buffer = System.Text.Encoding.ASCII.GetBytes(command);

//使用CreateFile外部函数连接到LPT1端口

SafeFileHandle printer = CreateFile( LPT1:,FileAccess.ReadWrite,0,IntPtr.Zero,FileMode.Open,0,IntPtr.Zero);

// Aqui verifico se aimpressoraéválida

if(printer.IsInvalid == true)

{

return;

}



///打开文件流到lpt1端口并发送命令

FileStream lpt1 = new FileStream(printer,FileAccess.ReadWrite);

lpt1.Write (buffer,0,buffer.Length);

//关闭FileStream co nnection



此代码使用但我在创建外部函数时出错..

- 错误:方法没有实现



static extern SafeFileHandle CreateFile(字符串lpFileName,FileAccess dwDesiredAccess,uint dwShareMode,IntPtr lpSecurityAttributes,FileMode dwCreationDisposition,uint dwFlagsAndAttributes,IntPtr hTemplateFile);

string command = "^XA^FO10,10,^AO,30,20^FDFDTesting^FS^FO10,30^BY3^BCN,100,Y,N,N^FDTesting^FS^XZ";

// Create a buffer with the command
Byte[] buffer = new byte[command.Length];
buffer = System.Text.Encoding.ASCII.GetBytes(command);
// Use the CreateFile external func to connect to the LPT1 port
SafeFileHandle printer = CreateFile("LPT1:", FileAccess.ReadWrite, 0, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
// Aqui verifico se a impressora é válida
if (printer.IsInvalid == true)
{
return;
}

/// Open the filestream to the lpt1 port and send the command
FileStream lpt1 = new FileStream(printer, FileAccess.ReadWrite);
lpt1.Write(buffer, 0, buffer.Length);
// Close the FileStream connection

this code use but i have given error in create external function..
--Error: Method has no implementation

static extern SafeFileHandle CreateFile(string lpFileName, FileAccess dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);

推荐答案

访问这里....



http://www.neodynamic.com/ND/FaqsTipsTricks.aspx?tabid=66&prodid=1&sid=59 [ ^ ]
visit here....

http://www.neodynamic.com/ND/FaqsTipsTricks.aspx?tabid=66&prodid=1&sid=59[^]


如果您试图让代码在ASP.NET场景中工作,那么忘记它,它将无法工作。

很抱歉,如果打印机连接到托管ASP.NET网站的服务器,可以工作。但是,如果您打算允许您的用户打印到他们的客户端打印机那么这将无效。

如果您想从ASP向客户端打印机发送原始打印机命令。 NET网站,然后您需要来自这个因为只使用ASP.NET框架无法做到这一点。
If you are trying to get that code to work in a ASP.NET scenario, then forget it, it won't work.
Sorry, that "could" work if the printer is attached to the server where your ASP.NET website is hosted. But that will not work if your intention is to allow your users to print to their client printers
If you want to send raw printer commands to the client printer from your ASP.NET website, then you'll need help from an external tool like this or this as there's no way to do that by using just ASP.NET framework.


您调用的API是否包含此方法?

也许您没有正确引用未损坏的dll。
Does the API you are calling contain this method?
Maybe you are not referencing the undamaged dll correctly.


这篇关于条码打印asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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