PrintService service = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = service.createPrintJob(); String command = "@PJL SET COPIES=3\n"; DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; byte[] bytes = command.getBytes(); Doc doc = new SimpleDoc(bytes, flavor, null); PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet(); attrs.add(PresentationDirection.TOBOTTOM); job.print(doc, attrs); 再添加设置彩色
时间: 2024-03-27 17:40:54 浏览: 121
Java-PrintService-Java打印-中文版API.docx
你可以在 `PrintRequestAttributeSet` 中添加 `Chromaticity.COLOR` 属性来设置彩色打印。修改后的代码如下所示:
```java
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = service.createPrintJob();
String command = "@PJL SET COPIES=3\n";
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
byte[] bytes = command.getBytes();
Doc doc = new SimpleDoc(bytes, flavor, null);
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
attrs.add(PresentationDirection.TOBOTTOM);
attrs.add(Chromaticity.COLOR); // 添加设置彩色属性
job.print(doc, attrs);
```
这样就同时实现了使用 PJL 设置打印机属性和设置彩色打印的需求。
阅读全文