【问题标题】:How can i open PDF file from SdCard in my Application programmatically but not in device installed PDFViewer?如何在我的应用程序中以编程方式从 SdCard 打开 PDF 文件,但不能在安装的设备中打开 PDFViewer?
【发布时间】:2014-03-22 13:02:42
【问题描述】:

我使用了很多库,但这些都是无用的,我还检查了 PDF 文件是否可以在 Web 视图中打开通过使用 ContenProviderURI 转换为 Html 代码/strong> 但这对我也不起作用。

我使用过类似的库

  • PDF 查看器
  • MuPDF 库
  • 还有更多...

所以,如果有人遇到过这个问题或有解决这个问题的方法,请帮我解决这个问题。

【问题讨论】:

    标签: android pdf android-webview


    【解决方案1】:

    我使用 PDFViewer 库 PDFViewer 解决了它 您需要做的就是:

    • 将 PDFViewer 项目导入您的工作区(或使用 PDFViewer.jar 文件)。
    • 将其添加为您项目的库。
    • 如下定义一个Activity:

      public class ViewerActivity extends PdfViewerActivity {
        public int getPreviousPageImageResource() { return R.drawable.left_arrow; }
        public int getNextPageImageResource() { return R.drawable.right_arrow; }
        public int getZoomInImageResource() { return R.drawable.zoom_in; }
        public int getZoomOutImageResource() { return R.drawable.zoom_out; }
        public int getPdfPasswordLayoutResource() { return R.layout.pdf_file_password; }
        public int getPdfPageNumberResource() { return R.layout.dialog_pagenumber; }
        public int getPdfPasswordEditField() { return R.id.etPassword; }
        public int getPdfPasswordOkButton() { return R.id.btOK; }
        public int getPdfPasswordExitButton() { return R.id.btExit; }
        public int getPdfPageNumberEditField() { return R.id.pagenum_edit; }
      

      }

    • 调用Activity如下:

      Intent intent = new Intent(this, MainActivity.class);
       intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, FILE_PATH);
       startActivity(intent);
      

    其中 FILE_PATH 是您设备上的 pdfFileLocation。 我的就像

    final String FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test/com_handbook.pdf"; 
    

    希望这会有所帮助。

    【讨论】:

    • 对不起,我用过,但有时它会显示PDF中的所有内容,有时会显示一半的内容,总之,它不会与显示内容一致。
    • @chiragpatel check outOfMemoryError
    • 对不起,但我已经检查了所有的可能性,最后我将从 PDF_Viewer 库中准备一个类并将 MyPdfFile.pdf 转换为位图,这是最好的选择。然后从 sdcard 中打开该位图图像,然后在 webview 中显示它。所以,这样我就解决了我的问题,我可以成功地显示我的 pdf 文件......
    猜你喜欢
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多