简体   繁体   English

如何在我的应用程序中以编程方式从SdCard打开PDF文件,但不能在已安装设备的PDFViewer中打开呢?

[英]How can i open PDF file from SdCard in my Application programmatically but not in device installed PDFViewer?

I Have used many of library but those all are Useless , I have also check weather the PDF file can be opened in Web-view By converting my URI to Html code using ContenProvider but that also isn't worked for me . 我已经使用了许多库,但是都没用,我还检查了可以在Web视图中打开PDF文件的情况,方法是使用ContenProviderURI转换为HTML代码,但这对我来说不起作用。

I have used libraries like 我用过像

  • PDF Viewer PDF查看器
  • MuPDF library MuPDF库
  • and many more... 还有很多...

So, please if anyone have faced this problem or have solution for this problem then Help me to solve this problem. 因此,如果有人遇到此问题或对此问题有解决方案,请帮助我解决此问题。

I solved it using PDFViewer library PDFViewer All you need to do is to: 我使用PDFViewer库PDFViewer解决了它,您所需要做的就是:

  • Import PDFViewer project to your workspace (or use PDFViewer. jar file). 将PDFViewer项目导入到您的工作区中(或使用PDFViewer.jar文件)。
  • Add it as library for your project. 将其添加为您的项目的库。
  • Define an Activity like follows: 定义一个活动,如下所示:

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

    } }

  • Call Activity like follows: 呼叫活动如下:

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

Where FILE_PATH is pdfFileLocation on your device. 其中FILE_PATH是设备上的pdfFileLocation。 Mine was like 我的就像

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM