Maybe not the best answer, but I recently did it like that. I connected the printer to the PC with Windows. Then I shared the printer. Then this shared printer I mapped into LPT1 via simple command (all of this can be done one one PC):
net use \\pcname\sharedprinter LPT1:
Since now this LPT1 port is aka file you can write to. Now I simply write data to that file in JAVA and it is working fine. I know it is not very elegant, but works for me and lets me use one label printer shared between a few PCs
public class EplPrint1 {
private final String port;
public EplPrint1(String port) {
this.port = port;
}
public void printLabel(String label, String company, String docDate) throws FileNotFoundException {
FileOutputStream os = new FileOutputStream(port);
PrintStream ps = new PrintStream(os);
String commands = "N\n"
+ "A1,1,0,1,1,1,N,\""+asciiNormalize(company)+"\"\n"
+ "A1,20,0,1,1,1,N,\""+asciiNormalize("Entry date")+": " + docDate+"\"\n"
+ "B1,40,0,1,3,2,80,B,\""+label+"\"\n"
+ "P1,1\n";
ps.println(commands);
ps.print("\f");
ps.close();
}
public static void main(String[] argv) throws FileNotFoundException {
//EplPrint1 p = new EplPrint1("d:\\tmp\\eplcommands.txt");
EplPrint1 p = new EplPrint1("LPT1");
//p.printLabel("23535.A.33.B.233445");
p.printLabel("label 12345", "Company name", "2013-05-10 12:45");
}
}
The example provided is for EPL printing, but ZPL should work the same way.