I'm writing an lpr client on java to send files (PDF, doc, etc) to a printer (hp laser-jet 4250dtn) Both client and server are running UNIX
The printer is on a server (that's why I'm using lpr) Everything is all right and I indeed managing to open the socket, sending the control file(according to RFC 1179) and sending the file itself.
the file is getting to the printer "queue".
My problem is when I want to print the file from the printer, it's comes out wrong and not understandable at all (can't see any text just weird symbols).
My question is what file type shout I give or make (change the file to postscript??) in order that the printer will understand me? Or am I doing anything else wrong?
Im attaching the code here so you can see and highlighted the line in which im opening the file from the file-path
Socket socketLpr = getSocket(hostName);
socketLpr.setSoTimeout(30000);
OutputStream sOut = socketLpr.getOutputStream();
InputStream sIn = socketLpr.getInputStream();
//Open printer
s = "\002" + printerName + "\n";
sOut.write(s.getBytes());
sOut.flush();
acknowledge(sIn, "lpr Failed to open printer");
//Send control file
controlFile += "H" + hostName + "\n";
controlFile += "P" + userName + "\n";
controlFile += ((printRaw) ? "o":"p") +"dfA" + strJobNumber + hostName + "\n";
controlFile += "UdfA" + strJobNumber + hostName + "\n";
controlFile += "N" + documentName + "\n";
s = "\002" + (controlFile.length()) + " cfA" + strJobNumber + hostName + "\n";
sOut.write(s.getBytes());
acknowledge(sIn, "lpr Failed to send control header");
buffer = controlFile.getBytes();
sOut.write(buffer);
buffer[0] = 0;
sOut.write(buffer, 0, 1);
sOut.flush();
acknowledge(sIn, "jLpr Failed to send control file");
//Send print file
**f = new File(fileName);** // <- here is when im oppening the file(pdf,word,etc)
if (!(f.exists() && f.isFile() && f.canRead())) {
throw new IOException("jLpr Error opening print file");
}
s = "\003" + (f.length()) + " dfA" + strJobNumber + hostName + "\n";
sOut.write(s.getBytes());
sOut.flush();
acknowledge(sIn, "jLpr Failed to send print file command");
FileInputStream fs = new FileInputStream(f);
int readCounter;
do {
readCounter = fs.read(buffer);
if (readCounter>0) {
sOut.write(buffer, 0, readCounter);
}
} while (readCounter>0);
buffer[0] = 0;
sOut.write(buffer,0,1);
sOut.flush();
acknowledge(sIn, "jLpr Failed to send print file");
socketLpr.close();
}