如何打印pdf文件?

时间:2018-10-15 08:56:07

标签: android printing itext

我的pdf创建路径。 我要打印此路径pdf文件。我要打印预览

如何获取外部路径。

字符串路径= Environment.getExternalStorageDirectory()。getAbsolutePath()+“ / Dir”;

        File dir = new File(path);
        if (!dir.exists())
            dir.mkdirs();

        File file = new File(dir, gettablevalue + "TableBill.pdf");
        FileOutputStream fOut = new FileOutputStream(file);

        PdfWriter.getInstance(doc, fOut);

        //open the document
        doc.open();

打印代码

 InputStream in = null;
            OutputStream out = null;
            try {


                out=new FileOutputStream(destination.getFileDescriptor());

                byte[] buf=new byte[16384];
                int size;

                while ((size=in.read(buf)) >= 0
                        && !cancellationSignal.isCanceled()) {
                    out.write(buf, 0, size);
                }

                if (cancellationSignal.isCanceled()) {
                    callback.onWriteCancelled();
                }
                else {
                    callback.onWriteFinished(new PageRange[] { PageRange.ALL_PAGES });
                }
            }
            catch (Exception e) {
                callback.onWriteFailed(e.getMessage());
                Log.e(getClass().getSimpleName(), "Exception printing PDF", e);
            }
            finally {
                try {
                    in.close();
                    out.close();
                }
                catch (IOException e) {
                    Log.e(getClass().getSimpleName(),
                            "Exception cleaning up from printing PDF", e);
                }
            }
        }
    }

0 个答案:

没有答案