我的热敏打印机有问题。每次我打印时,都会像这样添加一些代码/文本。
%!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);