使用PrintManager Android 4.4直接打印PDF [英] Printing PDF directly using PrintManager Android 4.4

查看:834
本文介绍了使用PrintManager Android 4.4直接打印PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://developer.android.com/training/printing/index.html 文档介绍了如何通过在PDF画布上呈现自定义内容并发送由此创建的PDF文档进行打印来打印自定义内容.但是没有关于我们是否已经有PDF文档,如何发送以进行打印的信息吗?

http://developer.android.com/training/printing/index.html documentation tells how to print a custom content by rendering it on a PDF canvas and sending thus created PDF document for printing. But has no information about if we already have a PDF document, how to send it for printing?

类似于位图打印,有诸如printHelper.printPDF之类的方法吗?

Does similar to bitmap printing, there is some method like printHelper.printPDF?

推荐答案

在onWrite()方法中使用以下代码片段即可:

Use the following code fragment in your onWrite() method should do it:

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();
    }
}

这篇关于使用PrintManager Android 4.4直接打印PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆