I am planing to use Eclipse and a simple swing gui to print raw data. My bar code printer uses .prn
files to print and all is encoded in the file so if I can manage to send the exact contents of the file to my printer as raw data, I can make it print the exact format I want. I can select the file and use StringBuffer
to read its contents and write to a string. Now how can I manage to send this string as raw data to my printer?
Regards.
edit:
Maybe i should elaborate my question a bit; now it works,in windows using;
int ch;
FileInputStream fin = null;
try {
fin = new FileInputStream(prnfile);
while ((ch = fin.read()) != -1)
strContent.append((char) ch);
fin.close();
JOptionPane.showMessageDialog(frame, strContent);
} catch (Exception e1) {
System.out.println(e1);
}
try {
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
JOptionPane.showMessageDialog(frame, service);
DocPrintJob job = service.createPrintJob();
InputStream is = new ByteArrayInputStream(strContent.toString().getBytes());
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(is, flavor, null);
job.print(doc, null);
is.close();
But when i try to run this in Ubuntu,i get only "printing cancelled,java printing " notification,and the printer does nothing (normally my printer works in ubuntu using cat xxx.prn | lpr
from the terminal.Any ideas?