【发布时间】:2014-03-24 11:09:28
【问题描述】:
我需要为我的打印机打印一个 pdf 文件。使用此代码,我已将我的 pdf 转换为 bytearray,但我被卡住了,不知道如何将其发送到打印机。有人可以帮助我吗?
File file = new File("java.pdf");
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
//Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
System.out.println("ERROR!");
}
byte[] bytes = bos.toByteArray();
提前谢谢你。
【问题讨论】:
-
查看我的回答here。可以使用套接字来完成这项工作
-
感谢您的回答,但还有其他可能,比如不是套接字?
标签: java android pdf zebra-printers