Android: How to open PDF without using the internet?

Asked

Viewed 386 times

1

How do I place a file .pdf on its own app, and open it without downloading using its URL? It would be all offline. Once the app was installed, .pdf would go along with him.

1 answer

1

Android has no support for PDF format, so it is necessary to use external libraries. A widely used is the Androidpdfviewer.

Below follows the step by step to use it

1) Add Pdfviewer.jar into your project’s build path

2) Copy the following drawable Resources from Pdfviewer/res/drawable into Yourproject/res/drawable left_arrow.png right_arrow.png zoom_in.png zoom_out.png

3) Copy the following layout Resources from Pdfviewer/res/layout into Yourproject/res/layout dialog_pagenumber.xml pdf_file_password.xml

4) Derive your PDF Activity from net.sf.andpdf.pdfviewer.PdfViewerActivity

5) Using the default drawables and layouts: 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; }

6) Invoke your Pdfviewactivity derived with the following code: Intent Intent = new Intent(this, Yourpdfvieweractivity.class); Intent.putExtra(Pdfvieweractivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE"); startActivity(Intent);

Source: README.txt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.