I have an ASP Web API and network printer(Epson TM-U220). I need to select the printer by code and print a bill. I just try as bellow. But not work fine. I want to print this direct using pos printer
var server = "192.168.1.164";
var nome = "www.pdf";
Socket clientSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
clientSocket.NoDelay = true;
IPAddress ip = IPAddress.Parse(server);
IPEndPoint ipep = new IPEndPoint(ip, 9100);
clientSocket.Connect(ipep);
clientSocket.Send(File.ReadAllBytes(nome));
clientSocket.Close();
CodePudding user response:
As many have commented, the Epson TM-U220 does not have the ability to print PDFs.
You need to convert the print content to an ESC/POS control sequence supported by the Epson TM-U220 before sending.
For example, this article and the libraries introduced there may be helpful.
Printing PDF doc to esc/pos Thermal printer
MoienTajik/EscPrinterSample
However, the Epson TM-U220 is a dot printer, and due to its low resolution and low printing speed, the above methods for thermal printers may not give comfortable results.
The printing example you have presented is for a thermal printer, and a dot printer cannot print such beautiful and detailed prints.
By the way, the commented Epson OPOS ADK for .NET v1.14.20E
is a client-side printing method, and it is very difficult to operate it on the server side.
What's more, simply embedding it requires understanding and addressing concepts and subsystems such as POS for.NET/OPOS.
Given the above situation, does the receipt need to be a PDF?
If it is okay to call the function to convert to ESC/POS control sequence instead at the timing of creating PDF, you may be able to use the following library.
lukevp/ESC-POS-.NET
ESCPOS.NET - Easy to use, Cross-Platform, Fast and Efficient.
Even if you use this library, you cannot directly specify printing of PDF.
Print pdf file #13
As mentioned in the above issue, it is possible to convert PDF to PNG using an application or another library and then call the above library, but it will take time and the print result will be poor.
HOW TO CONVERT PDF TO PNG IN C# .NET?