我在热敏打印机中遇到问题。每次打印时,都会添加一些代码/文本。
%!PS-Adobe-3.0
%%BoundingBox: 17 19 595 773
%%Pages: 1
.....
%%BegingFeature: *InputSlot Upper
2 dict up /PageSize [612 792] put dup /ImagingBox null put setpagedevice
%%EndFeature
....
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
%%EndPageSetup
%%BeginDocument: nondsc
Hello World
%%EndDocument
%%EOF
我只想打印“Hello World”,如何消除输出中不需要的文本?我的代码中有什么东西吗?
我的打印机是ESC / POS 型号P06-P 我的平台:Mac OS 10.8.2
我的代码是
String defaultPrinter = PrintServiceLookup.lookupDefaultPrintService().getName();
System.out.println("Default printer: " + defaultPrinter);
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
// prints the famous hello world! plus a form feed
InputStream is = new ByteArrayInputStream("hello world!\f".getBytes("UTF8"));
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(is, flavor, null);
DocPrintJob job = service.createPrintJob();
job.print(doc, pras);
is.close();
任何帮助将不胜感激
=======================================
当我尝试在CLI上打印它时会打印出来,但是当我在java中创建这个代码时,它没有打印出来。 waitFor()总是返回1.我确定文件在那里,以及它正在执行的目录。但是当我只发出“ls”时,它会有一个输出。
List<String> cmd = new ArrayList<String>();
cmd.add("lpr");
cmd.add("-P");
cmd.add("Prolific_Technology_Inc__IEEE_1284_Controller");
cmd.add("-oraw");
cmd.add("lalala.txt");
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.directory(new File("src/org/cups4j/test"));
Process p = pb.start();
int res = p.waitFor();
String line = null;
try {
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while( (line = input.readLine()) != null){
System.out.println(line);
}
} catch (IOException e1) {
e1.printStackTrace();
System.exit(0);
}
System.out.println("Result: " + res);
答案 0 :(得分:0)
您可能会在打印机的(程序员)手册中找到正确的转义序列。
// ouput an escape sequence
byte ESC = 0x1b;
FileOutputStream out = new FileOutputStream("lalala.txt");
byte[] buf = new byte[]{ESC,0x31};
out.write(buf);
out.close();