简体   繁体   中英

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 .

I have used libraries like

  • PDF Viewer
  • MuPDF library
  • 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:

  • Import PDFViewer project to your workspace (or use PDFViewer. jar file).
  • 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. Mine was like

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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