在App中显示PDF文件
我发现这两种可能性来显示一个PDF文件。
用以下方式打开webView:
 webView.loadUrl("https://docs.google.com/gview?embedded=true&url="+uri); 
用extern打开pdf文件App:
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(不过outFile), “应用/ PDF”); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(意向);
他们两人都工作。 但我的问题是,pdf仅供内部使用,在这两个示例中,用户可以下载它或将其保存在另一个文件夹中。
我知道在iOS开发中使用的框架,我正在寻找一种适用于Android的解决方案。
Android现在提供了PDF API,可以很容易地在应用程序中呈现PDF内容。
你可以在这里找到细节
以下是从assets文件夹中的pdf文件进行渲染的示例片段。
    private void openRenderer(Context context) throws IOException {
    // In this sample, we read a PDF from the assets directory.
    File file = new File(context.getCacheDir(), FILENAME);
    if (!file.exists()) {
        // Since PdfRenderer cannot handle the compressed asset file directly, we copy it into
        // the cache directory.
        InputStream asset = context.getAssets().open(FILENAME);
        FileOutputStream output = new FileOutputStream(file);
        final byte[] buffer = new byte[1024];
        int size;
        while ((size = asset.read(buffer)) != -1) {
            output.write(buffer, 0, size);
        }
        asset.close();
        output.close();
    }
    mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    // This is the PdfRenderer we use to render the PDF.
    if (mFileDescriptor != null) {
        mPdfRenderer = new PdfRenderer(mFileDescriptor);
    }
}
更新:这段代码来自谷歌开发者提供的样本。
许多库可用于在您自己的应用程序中显示PDF。
  有关使用android-pdfView的工作示例,请参阅此博客文章。  它演示了库的基本用法,通过垂直和水平滑动将pdf显示在视图上。 
pdfView = (PDFView) findViewById(R.id.pdfView);
pdfView.fromFile(new File("/storage/sdcard0/Download/pdf.pdf")).defaultPage(1).enableSwipe(true).onPageChange(this).load();
您可以在自己的查看器中显示PDF
层级是你应该看看的几个开源PDF查看器:http://androiddeveloperspot.blogspot.com/2013/05/android-pdf-reader-open-source-code.html
您可以加密PDF并确保您的查看器只能解密它。
链接地址: http://www.djcxy.com/p/67507.html上一篇: Show PDF file in App
下一篇: android trouble with saving pictures to internal memory
