android - 直接使用 PrintManager Android 4.4 打印 PDF

标签 android pdf printing android-4.4-kitkat android-print-framework

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/

相关文章:

android - yasm/nasm 未找到或太旧。使用 --disable-yasm 进行残废的构建

android - 如何在 React Native 中更改 TextInput 占位符的样式?

c - 为什么 printf 打印错误的值?

javascript - 用于可打印 HTML 表单的 HTML+CSS+Javascript 框架?

macos - 如何为 Mac OSX 编写虚拟打印机驱动程序

android - 有什么方法可以使用 cursoradapter 在 recyclerview 中实现字母部分索引?

android - 如何在FlatList React Native中实现复选框

ios - 使用 UIKit/Coregraphics 渲染为 PDF 时图像模糊

php - 使用 PS (postscript) 文件将转义码打印到打印机

pdf - 为什么在我将 svg 转换为 pdf 时 dominant-baseline 不起作用?