Quick start incorporating a PDF viewing activity into your project:

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:

[sourcecode language=”java”]

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

[/sourcecode]

6) Invoke your PdfViewActivity derived with the following code:

[sourcecode language=”java”]

Intent intent = new Intent(this, YourPdfViewerActivity.class);

intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE");

startActivity(intent);

[/sourcecode]

Download the source code and demo code from below link here

 

 

EDIT:  Another pdf viewer source for free  at github.

https://github.com/rameshakulapc/PDFViewer

Find the reference  Post by Andhradroid.

How to display the pdf in Android ?
Tagged on:                                     

17 thoughts on “How to display the pdf in Android ?

  • July 29, 2012 at 7:08 pm
    Permalink

    it is giving an error when it runs on emulator “FORCE CLOSE” I dont know whats wrong…

    Reply
  • July 30, 2012 at 3:51 am
    Permalink

    Can u give me the more explanation where u s trucked ? I have tested it in 2.3 emulator, its working fine for me.Had u tested with my source code. I have added library and demo projects.

    Reply
  • July 30, 2012 at 10:56 am
    Permalink

    same i have got error here log …plz share whole code for view PDF
    07-30 13:46:33.421: E/AndroidRuntime(6092): FATAL EXCEPTION: main
    07-30 13:46:33.421: E/AndroidRuntime(6092): java.lang.RuntimeException: Failed to register input channel. Check logs for details.
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.view.InputQueue.nativeRegisterInputChannel(Native Method)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.view.InputQueue.registerInputChannel(InputQueue.java:92)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.view.ViewRoot.setView(ViewRoot.java:572)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:207)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:121)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.view.Window$LocalWindowManager.addView(Window.java:424)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2174)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.os.Handler.dispatchMessage(Handler.java:99)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.os.Looper.loop(Looper.java:123)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at android.app.ActivityThread.main(ActivityThread.java:3687)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at java.lang.reflect.Method.invokeNative(Native Method)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at java.lang.reflect.Method.invoke(Method.java:507)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    07-30 13:46:33.421: E/AndroidRuntime(6092): at dalvik.system.NativeStart.main(Native Method)

    Reply
  • August 1, 2012 at 9:11 pm
    Permalink

    yes me too got the same error please help me out in android pdf reader Thank You

    Reply
  • December 10, 2012 at 4:14 pm
    Permalink

    Is it possible to use it with pdfs stored inside assets folder? because I’ve tried to replace “/mnt/…” with “file:///android_asset/…” and didn’t work.

    Reply
  • June 3, 2013 at 4:26 am
    Permalink

    jus right click pdfviewer demo and click on properties…there click on android and on the right side bottom click on add button to add the library project…once the library project is added click apply and then ok…and bingo…the project runs successfully….
    But there is one problem…when i load a pdf file inmany of the files there is an error of ttf fonts showing due to which pdf becomes corrupted and cat be viewed completely…any solution for that….???

    Reply
  • June 17, 2013 at 4:28 pm
    Permalink

    In your code, the path to PDF is specified as below:
    intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME,
    “mnt/sdcard/sample.pdf”);

    I want to embed PDF in the application code itself. My question is where should I copy sample.pdf file in my project? What should be the path in the above statement?

    Reply
  • March 5, 2014 at 6:42 pm
    Permalink

    have some issue. on Android 4.4.2 i have “Loading PDF Page” all the time. where on Android 2.3.3 everything OK.

    Reply
  • August 7, 2014 at 2:40 pm
    Permalink

    Not working in Android OS 4.4.4

    Reply
  • August 31, 2014 at 6:34 pm
    Permalink

    Superb, what a web site it is! This weblog provides helpful data to us, keep
    it up.

    Reply
  • September 16, 2014 at 9:24 am
    Permalink

    i am using it. i need to change the layout of pdfviewer. is it possible?

    Reply
  • June 18, 2015 at 12:54 am
    Permalink

    People facing issues with the demo, please don’t forget to include permissions to read storage in manifest file.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *