I want to print using IP address. I have followed example shared Print to a network printer using IP address but am unable to print. There is no error either. Here is the code I have written:
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Net;
using System.Net.Sockets;
using System.Printing;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
namespace PrinterManager
{
public class NetworkPrinter
{
private readonly string ip;
private readonly int _port;
public NetworkPrinter(string IPAddress,int port)
{
ip = IPAddress;
_port = port;
}
public void Print(string fileContent)
{
var client = new TcpClient();
client.Connect(ip.ToString(), _port);
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream(), Encoding.UTF8);
writer.Write(fileContent);
writer.Flush();
writer.Close();
client.Close();
}
}
}
Just to mention, am using HP Color LaserJet Pro MFP M177fw.