有没有人有向打印机发送字节数组的经验?我将pdf文件直接发送到打印机的IP地址,它在某些打印机上打印,而在其他打印机上打印空白页。这是打印机驱动程序问题吗?这是打印的代码:
public class PrintService : IPrintService
{
ManualResetEvent connectDone;
ManualResetEvent sendDone;
/// <inheritDoc />
public void PrintData(byte[] data, string printerName)
{
connectDone = new ManualResetEvent(false);
sendDone = new ManualResetEvent(false);
IPAddress ip = IPAddress.Parse(printerName);
IPEndPoint remoteEP = new IPEndPoint(ip, 9100);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.NoDelay = true;
try
{
client.BeginConnect(remoteEP, new AsyncCallback(connectCallback), client);
connectDone.WaitOne();
client.BeginSend(data, 0, data.Length, 0, new AsyncCallback(sendCallback), client);
sendDone.WaitOne();
}
finally
{
// Shutdown the client
this.shutDown(client);
}
}
private void connectCallback(IAsyncResult ar)
{
// Retrieve the socket from the state object.
Socket client = (Socket)ar.AsyncState;
// Complete the connection.
client.EndConnect(ar);
// Signal that the connection has been made.
connectDone.Set();
}
private void sendCallback(IAsyncResult ar)
{
// Retrieve the socket from the state object.
Socket client = (Socket)ar.AsyncState;
// Complete sending the data to the remote device.
int bytesSent = client.EndSend(ar);
// Signal that all bytes have been sent.
sendDone.Set();
}
private void shutDown(Socket client)
{
client.Shutdown(SocketShutdown.Both);
client.Close();
}
}
最佳答案
因此,在尝试了其他所有类的感觉(PrintDocument
,PrintServer
,ProcessInfo
和adobe/foxit
)之后,将文件直接复制到打印机,使用DLLImport[Kernetl32.dll]
在端口上创建文件,使用GCHandle
和pointers
,我将注意力集中在与打印机设置。对于特定的打印机,我有以下这些步骤可以使我的原始代码正常工作:
....
填满屏幕并消失关于c# - 使用套接字打印到IP地址和字节数组在某些打印机上打印空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27926649/