http://developer.android.com/training/printing/index.html文档说明如何通过在 PDF Canvas 上呈现自定义内容并发送创建的 PDF 文档进行打印来打印自定义内容。但是没有关于如果我们已经有 PDF 文档,如何发送它进行打印的信息?
有没有类似于位图打印的类似printHelper.printPDF的方法?
最佳答案
在您的 onWrite() 方法中使用以下代码 fragment 应该可以做到这一点:
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();
}
}
关于android - 直接使用 PrintManager Android 4.4 打印 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19727695/