我在这里问你解决这个问题的方法:
我有这段代码:
public void print(String ip, int port, String printService, byte[] message, String jobName) throws PrinterException{
PrintService service = getPrintService(printService);
try {
Doc doc = new SimpleDoc(message, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
DocPrintJob job = service.createPrintJob();
PrintRequestAttributeSet arset = new HashPrintRequestAttributeSet();
arset.add(convertMediaSize(mediaSize));
arset.add(Finishings.STAPLE);
arset.add(MultipleDocumentHandling.SEPARATE_DOCUMENTS_COLLATED_COPIES);
arset.add(convertPageSides(pageSides));
arset.add(new Copies(copies==0?1:copies));
job.print(doc, arset);
} catch (Exception e) {
throw new PrinterException(e);
}
}
消息是从PDF生成的字节数组
当我在佳能iR-ADV 400/500 PLC5e(设置为默认打印机)上执行此代码打印时输出正常。
当我在佳能iR-ADV c5235 / 5240 PCL5c上执行此代码打印时,输出的是很多充满奇怪字符的页面:
strange chars
如果我尝试使用word或Notepad或Acrobat Reader在两台打印机上打印,则两台打印机都是同一网络中的网络打印机...输出正常。
我正在尝试从Windows打印,而不是从Linux打印。
“message”以这种方式生成(在我的测试中)
File file = new File(inputFile);
byte[] b = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(b);
wp.print(null, 0, printService, b, null);
有什么想法吗? 感谢