http://developer.android.com/training/printing/index.html http://developer.android.com/training/printing/index.html文档介绍了如何通过在 PDF 画布上渲染自定义内容并发送由此创建的 PDF 文档进行打印来打印自定义内容。但是没有关于如果我们已经有 PDF 文档,如何发送它进行打印的信息?
与位图打印类似,是否有类似 printHelper.printPDF 的方法?
在 onWrite() 方法中使用以下代码片段应该可以做到这一点:
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(new File("somefile.pdf"));
output = new FileOutputStream(destination.getFileDescriptor());
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
} catch (Exception e) {
} finally {
try {
input.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)