add PDFViewer as a library to your project, copy your resources to yours as described in HERE. This is working code for me. I am reading pdf from the data folder. Make the customization as your requirement. 1. Download the PDF reader project from the link above. 2. Copy all resources to your project. 3. Expand your activity (in which you want to display pdf) from PdfViewerActivity. 4. Copy all the methods from the pdfreader project into your activity. 5.Run. Happy coding
AssetManager assetManager = getAssets(); InputStream in = null; OutputStream out = null; File file = new File(getFilesDir(), "ABC.pdf"); try { in = assetManager.open("ABC.pdf"); out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch (Exception e) { Log.e("tag", e.getMessage()); } Intent intent = new Intent(this, YourNextActivityName.class); intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, getFilesDir() + "/ABC.pdf"); startActivity(intent); } private void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } }
Yourpdfview Activity Methods
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; }
shivpal jodha May 11 '15 at 11:21 2015-05-11 11:21
source share