Wednesday, March 20, 2013

Android PDF viewer Application

we can make an easy pdf viewer in few easy steps. create a project with the name PDFVIEW and have a main activity as 
 we need a library for this project available at https://github.com/jblough/Android-Pdf-Viewer-Library

never forget to add this library in the project given here

1) MainActivity.java


package com.example.pdfview;

import java.io.File;
import java.io.FilenameFilter;

import net.sf.andpdf.pdfviewer.PdfViewerActivity;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ListActivity {

    String[] pdflist;
    File[] imagelist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        File images = Environment.getExternalStorageDirectory();
        imagelist = images.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return ((name.endsWith(".pdf")));
            }
        });
        pdflist = new String[imagelist.length];
        for (int i = 0; i < imagelist.length; i++) {
            pdflist[i] = imagelist[i].getName();
        }
        this.setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, pdflist));
    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String path = imagelist[(int) id].getAbsolutePath();
        openPdfIntent(path);
    }

    private void openPdfIntent(String path) {
        try {
            final Intent intent = new Intent(MainActivity.this, Second.class);
            intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

2) Second .java


package com.example.pdfview;

import net.sf.andpdf.pdfviewer.PdfViewerActivity;
import android.os.Bundle;

public class Second extends PdfViewerActivity {

public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}

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

screen shots

1


 2
3

The manifest is as given below


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.pdfview"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.pdfview.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="Second"></activity>
    </application>

</manifest>



Download the project code at CODE

90 comments:

  1. Can i add my button to view second?

    ReplyDelete
  2. Replies
    1. Yes you can do those things in a customize way. i will send you the code snippet soon after implementing the functionality if i will get the success :)

      Delete
  3. Hi when I run this project it shows white page and doesn't do anything. what's the reason?
    thank you

    ReplyDelete
    Replies
    1. obviously it will show a white screen only, please get some pdf documents on yours sd card. get some PDF documents and put them at SD Card.

      Delete
    2. u must have not declared your second class in the manifest

      Delete
  4. I want to put pdf file in res/raw folder.
    which part of the code should be changed?
    please say it clearly ,I'm new developer in android

    ReplyDelete
    Replies
    1. Please see the function/method

      private void openPdfIntent(String path) {
      try {
      final Intent intent = new Intent(MainActivity.this, Second.class);
      intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
      startActivity(intent);
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      choose path from asset now for which==>


      if you have a reference to any Context subclass, such as an Activity, you can get a reference to the AssetManager instance provided by the platform:

      AssetManager assetManager = getAssets();

      Once you have an AssetManager reference, you can just open a raw InputStream for any asset you put into the assets directory like this:


      InputStream stream = null;
      try {
      stream = assetManager.open("pdf file path");
      } catch (IOException e) {
      // handle
      }


      Of course, you have to close the stream in finally, as in any Java application:


      finally {
      if (stream != null) {
      try {
      stream.close();
      } catch (IOException e) {}
      }
      }



      Unlike Resources, Assets can have any filename that is supported by OS and can be organized into subfolders in the assets directory. However, the only thing you can do with an asset is get an input stream. Thus, it does not make much sense to store your strings or bitmaps in assets, but you can store custom-format data such as input correction dictionaries or game maps. In fact, Android platform designers took care to support most of your app resource use cases within the Resources framework, so you won’t need to use Assets at all in most typical apps.

      Delete
  5. Good post I am able to render PDF, But I am little worried about the language support and also this solution is not showing the exact PDF as showing on Destop or Adobe Reader.

    Any Idea how many languages are supported ?

    --
    Rahul Pundhir

    ReplyDelete
    Replies
    1. Hi,as you can see in given post there is a screenshot of hindi specific book pdf reading so i can say that the language i should support on pdf itself, than language will be of no problem on the application and i checked that comics will be rendered in good way as well. you can use custom list to show all pdf with some icon, it is all about yours custom development.

      Delete
  6. When I click on PDf file
    I got following error and app crashes.

    10-01 13:24:26.250: D/AndroidRuntime(19087): Shutting down VM
    10-01 13:24:26.250: W/dalvikvm(19087): threadid=1: thread exiting with uncaught exception (group=0x40018578)
    10-01 13:24:26.265: E/AndroidRuntime(19087): FATAL EXCEPTION: main
    10-01 13:24:26.265: E/AndroidRuntime(19087): java.lang.NoClassDefFoundError: com.example.pdfview.Second
    10-01 13:24:26.265: E/AndroidRuntime(19087): at com.example.pdfview.MainActivity.openPdfIntent(MainActivity.java:76)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at com.example.pdfview.MainActivity.onListItemClick(MainActivity.java:71)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.widget.ListView.performItemClick(ListView.java:3736)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1974)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.os.Handler.handleCallback(Handler.java:587)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.os.Handler.dispatchMessage(Handler.java:92)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.os.Looper.loop(Looper.java:130)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at android.app.ActivityThread.main(ActivityThread.java:3687)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at java.lang.reflect.Method.invokeNative(Native Method)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at java.lang.reflect.Method.invoke(Method.java:507)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    10-01 13:24:26.265: E/AndroidRuntime(19087): at dalvik.system.NativeStart.main(Native Method)

    thank you

    ReplyDelete
    Replies
    1. i seen the logs please try==>To fix this problem you need to:

      Create a named "libs" folder in the project. 2 Import libraries you need the project to this new folder. 2.1. To import them: right click in the libs folder--> import--> file system--> select the .jar and accept.
      Clean and build and boot

      Delete
  7. Hi,

    I am trying to load PDF from my device using above given code... it is not working...
    It is alwaysing showing as "Loading PDF Page"...

    Could you please help me to resolve the same?

    Thanks

    ReplyDelete
    Replies
    1. Hi deep can i have some debug logs that it will be better to know where the problem came?

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. 10-10 14:37:50.421: E/PDFVIEWER(319): null
    10-10 14:37:50.421: E/PDFVIEWER(319): java.lang.NullPointerException
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.content.ContentResolver.openInputStream(ContentResolver.java:431)
    10-10 14:37:50.421: E/PDFVIEWER(319): at net.sf.andpdf.pdfviewer.PdfViewerActivity.storeUriContentToFile(PdfViewerActivity.java:887)
    10-10 14:37:50.421: E/PDFVIEWER(319): at net.sf.andpdf.pdfviewer.PdfViewerActivity.onCreate(PdfViewerActivity.java:199)
    10-10 14:37:50.421: E/PDFVIEWER(319): at com.example.pdfview.Second.onCreate(Second.java:21)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.app.Activity.performCreate(Activity.java:5008)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2029)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2090)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.app.ActivityThread.access$600(ActivityThread.java:136)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.os.Handler.dispatchMessage(Handler.java:99)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.os.Looper.loop(Looper.java:137)
    10-10 14:37:50.421: E/PDFVIEWER(319): at android.app.ActivityThread.main(ActivityThread.java:4800)
    10-10 14:37:50.421: E/PDFVIEWER(319): at java.lang.reflect.Method.invokeNative(Native Method)
    10-10 14:37:50.421: E/PDFVIEWER(319): at java.lang.reflect.Method.invoke(Method.java:511)
    10-10 14:37:50.421: E/PDFVIEWER(319): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
    10-10 14:37:50.421: E/PDFVIEWER(319): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
    10-10 14:37:50.421: E/PDFVIEWER(319): at dalvik.system.NativeStart.main(Native Method)
    10-10 14:37:50.421: I/PDFVIEWER(319): ST='file 'no file selected' not found'
    10-10 14:37:50.431: V/AudioStreamOutALSA(170): write:: buffer 0x40533e38, bytes 2048
    10-10 14:37:50.441: I/PDFVIEWER(319): ST='reading page 1, zoom:1.0'

    ReplyDelete
  10. hi

    I have got this pdf working but i need a scroll view to view next pages using scrollview instead of clicking on right or left arrows. I wanted to know if it is possible without changing the PdfViewerActivity class.

    Can you please guide me with this?

    Thanks

    ReplyDelete
    Replies
    1. You need to go for Gestures. You will have callback methods like

      onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY)
      onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY)

      please try with them!!

      Delete
  11. Hello, how can I get action bar in this Second Activity which extends PdfViewerActivity. Please guide.

    ReplyDelete
  12. Hi in android for the action bar you can make a custom one or take the help of ABS library. you can make a custom bar with your needed actions. if need more help , i can send you some stuff regarding action bar in a custom way

    ReplyDelete
    Replies
    1. Hi,
      Thnks for reply. I know about action bar. Actually i want to add sherlock action bar in activity for some option in this Second Activity which is extending PdfViewerActivity. Do you have any idea how could I use both PdfViewerActivity and SherlockActivity for sherlock action support.

      Delete
    2. PdfViewerActivity activity can extend SherlockActivity and use some corresponding interfaces and you can proceed with this direction.

      Delete
  13. Hello sir,
    Can you tell me how to get the current page number of pdf .

    ReplyDelete
    Replies
    1. Hi Saurabh please investigate api of the library, there are some method regarding the page number and related stuff.

      Delete
  14. hi sir,
    can you help me, my console error;

    [2014-01-27 02:27:17 - Dex Loader] Unable to execute dex: Multiple dex files define Landroswing/tree/DefaultMutableTreeNode;
    [2014-01-27 02:27:17 - PDFVIEW] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroswing/tree/DefaultMutableTreeNode;

    ReplyDelete
    Replies
    1. hi please look regarding yours jar dependencies!! please google with keyword/phrase " Unable to execute dex: Multiple dex files", you will get yours answer!! this problem is because jar dependencies you used!!

      Delete
  15. Hi sir,
    I able to see pdf in list bt when i click on it it throws Class Not Found Exception

    01-28 22:53:05.414: W/dalvikvm(29048): Unable to resolve superclass of Lcom/example/pdfview/Second; (549)
    01-28 22:53:05.414: W/dalvikvm(29048): Link of class 'Lcom/example/pdfview/Second;' failed
    01-28 22:53:05.414: E/dalvikvm(29048): Could not find class 'com.example.pdfview.Second', referenced from method com.example.pdfview.MainActivity.openPdfIntent
    01-28 22:53:05.414: W/dalvikvm(29048): VFY: unable to resolve const-class 468 (Lcom/example/pdfview/Second;) in Lcom/example/pdfview/MainActivity;
    01-28 22:53:05.414: D/dalvikvm(29048): VFY: replacing opcode 0x1c at 0x0002
    01-28 22:53:05.414: D/dalvikvm(29048): VFY: dead code 0x0004-000e in Lcom/example/pdfview/MainActivity;.openPdfIntent (Ljava/lang/String;)V
    01-28 22:53:22.593: W/KeyCharacterMap(29048): Can't open keycharmap file
    01-28 22:53:22.593: W/KeyCharacterMap(29048): Error loading keycharmap file
    01-28 22:53:22.593: W/KeyCharacterMap(29048): Using default keymap
    01-28 22:58:26.867: W/dalvikvm(29707): Unable to resolve superclass of Lcom/example/pdfview/Second; (549)
    01-28 22:58:26.867: W/dalvikvm(29707): Link of class 'Lcom/example/pdfview/Second;' failed
    01-28 22:58:26.867: E/dalvikvm(29707): Could not find class 'com.example.pdfview.Second', referenced from method com.example.pdfview.MainActivity.openPdfIntent
    01-28 22:58:26.867: W/dalvikvm(29707): VFY: unable to resolve const-class 468 (Lcom/example/pdfview/Second;) in Lcom/example/pdfview/MainActivity;
    01-28 22:58:26.867: D/dalvikvm(29707): VFY: replacing opcode 0x1c at 0x0002
    01-28 22:58:26.867: D/dalvikvm(29707): VFY: dead code 0x0004-000e in Lcom/example/pdfview/MainActivity;.openPdfIntent (Ljava/lang/String;)V
    01-28 22:58:28.992: D/AndroidRuntime(29707): Shutting down VM
    01-28 22:58:28.992: W/dalvikvm(29707): threadid=1: thread exiting with uncaught exception (group=0x40018578)
    01-28 22:58:29.007: E/AndroidRuntime(29707): FATAL EXCEPTION: main
    01-28 22:58:29.007: E/AndroidRuntime(29707): java.lang.NoClassDefFoundError: com.example.pdfview.Second
    01-28 22:58:29.007: E/AndroidRuntime(29707): at com.example.pdfview.MainActivity.openPdfIntent(MainActivity.java:48)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at com.example.pdfview.MainActivity.onListItemClick(MainActivity.java:43)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.widget.ListView.performItemClick(ListView.java:3736)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1975)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.os.Handler.handleCallback(Handler.java:587)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.os.Handler.dispatchMessage(Handler.java:92)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.os.Looper.loop(Looper.java:130)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at android.app.ActivityThread.main(ActivityThread.java:3687)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at java.lang.reflect.Method.invokeNative(Native Method)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at java.lang.reflect.Method.invoke(Method.java:507)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    01-28 22:58:29.007: E/AndroidRuntime(29707): at dalvik.system.NativeStart.main(Native Method)

    ReplyDelete
    Replies
    1. Right Click on your Project then

      Goto Build Path-> Configure Build Path -> Order and Export

      when you are there you should check the Android Private Libraries and then click OK.

      if you still face the problem delete all the files inside your bin folder and rebuilt you project.

      To make sure your jar is actually exported at build, you should either:

      put it in the libs folder
      or fill the checkbox corresponding to your jar in project properties > Java build path > Order and export tab

      Delete
  16. Not able to view pdf file. blank screen

    01-29 19:58:43.568: I/PDFVIEWER(8994): onCreate
    01-29 19:58:43.568: E/PDFVIEWER(8994): restoreInstance
    01-29 19:58:43.598: I/PDFVIEWER(8994): Intent { cmp=com.news.lokrajya/.LokrajyaPDFViewActivity (has extras) }
    01-29 19:58:43.608: I/PDFVIEWER(8994): ST='file '/storage/emulated/0/-2032773965.pdf' has 54836 bytes'
    01-29 19:58:43.618: I/PDFVIEWER(8994): ST='Anzahl Seiten:10'
    01-29 19:58:43.618: I/PDFVIEWER(8994): ST='reading page 1, zoom:1.0'
    01-29 19:58:43.758: D/dalvikvm(8994): GC_FOR_ALLOC freed 451K, 7% free 20058K/21444K, paused 14ms, total 14ms
    01-29 19:58:43.818: D/dalvikvm(8994): GC_FOR_ALLOC freed 2340K, 14% free 18569K/21444K, paused 14ms, total 14ms
    01-29 19:58:43.818: I/dalvikvm-heap(8994): Grow heap (frag case) to 19.118MB for 1000806-byte allocation
    01-29 19:58:43.838: D/dalvikvm(8994): GC_FOR_ALLOC freed 2K, 9% free 19544K/21444K, paused 14ms, total 14ms

    ReplyDelete
  17. hey how to pdf open using assets folder

    ReplyDelete
  18. Hello Jitesh..
    Very well explained.. we have been looking for a pdf viewer to customize and nothing worked so good and was so apt for our work.
    I just have a problem that this works nicely on JellyBean and lower versions,.. but when i tried to run it on Android Kitkat supporting Nexus 4 it unfortunately stops. I have done the changes in the Manifest file for the target sdk version as 19.. and also checked the android 4.4.2 checkbox for the project in the project properties.. but still it wont work.. Please Help..!!

    ReplyDelete
    Replies
    1. Hi again..
      The above issue has been solved..
      The error was that you need to specify permissions in the manifest file to access external storage in case of Android Kitkat.. while in other versions it works even without the permission.
      Happy Coding..!! Thanks again for the Great tutorial..:)

      Delete
    2. sorry that i did not seen the problem when you send the message but if it is solved than it is great to know!!

      Delete
    3. hi Priya..
      To display AndroidPdfViewer in KitKat Which Permissions You are Giving on Manifest File..Please Help Me.

      Delete
  19. hey i want to open using assets folder how can i open ?

    ReplyDelete
  20. hi..
    i wanted to run a camera app in bckground of the pdf viewer.. i.e. i need to capture pictures of user.. and process it.. I have a working code for this.. but how do i send it to the background of this reader. Also do i have to make changes in the layout of the reader for adding the surface view and frame layout.. if yes then where cn i make these changes so that they reflect when i run the app..

    ReplyDelete
  21. how can i access a method used in the pdfviewerlibrary in second.java?

    ReplyDelete
    Replies
    1. please have a look at PdfViewerActivity documentation what you can do is extend the PdfViewerActivity and use them or override them according to yours use!!

      Delete
  22. Hello,

    Is there any way in which i can load multiple pages together? Currently it shows only 1 page with an option to navigate (next/previous).

    Thanks in advance! :)

    ReplyDelete
    Replies
    1. To reply to my own question, this library does not allow rendering multiple pages simultaneously.

      Used muPDF. Much faster, much simpler.

      Delete
    2. Many thanks Atul for the finding , i will also try with that, can you please give me the link of that library!!

      Delete
  23. Hi Jitesh,

    I have used your solution. It works wonderfully well with pdf files without password. For pdf Files with password the Bountycastle library has to be replaced with SpongeCastle Library( https://github.com/rtyley/spongycastle) . But there is a problem in rendering images in a pdf file. Most of the images are not rendered properly.

    ReplyDelete
  24. Thank you for nice tutorial @Jitesh (y)

    ReplyDelete
  25. Hi,

    Its loading page by page. I want to avoid that one loading page by page

    could i customize the code.. I f possible means can u guide me?

    ReplyDelete
  26. It is possible to view the pdf inside a fragment or framelayout so that it appears like it is embedded within the activity? Please advice

    ReplyDelete
  27. Getting Error on this line

    pdflist = new String[imagelist.length];

    at com.example.pdfview.MainActivity.onCreate(MainActivity.java:32)

    ReplyDelete
  28. can we use Pdf Viewer In Fragment If Yes ..Then How .?..I m Following Ur Blog
    i dont Want Go From Here With Upset Mood ... plzzz

    ReplyDelete
  29. it shows only Loading PDF Pages.... Please help

    ReplyDelete
  30. I'm getting my pDF file opened in an unreadable form.(Something like an inverted way)

    ReplyDelete
  31. Hi!! Could be possible to add pinch-zoom function in this activity, instead of using the existing but uneasy zoom buttons? Thanks

    ReplyDelete
    Replies
    1. How do I modify PdfViewerActivity, where methods are, if it is derivated from an external source?

      Delete
    2. Hi You can check the source code/api of the lib file and you will be able to solve yours problems. a long back i used the lib so do not remember.Also check for a neewer version http://upadhyayjiteshandroid.blogspot.in/2015/02/android-pdfview.html .

      Delete
  32. Hi You can check the source code/api of the lib file and you will be able to solve yours problems. a long back i used the lib so do not remember.Also check for a neewer version http://upadhyayjiteshandroid.blogspot.in/2015/02/android-pdfview.html .

    ReplyDelete
  33. This comment has been removed by the author.

    ReplyDelete
  34. hi can i use url instead of filepath in thid code? if yes how. becz when i m using url it is not working.

    ReplyDelete
  35. hello sir, i followed your steps and i have implemented it and also it works perfectly. but how can i remove right hand side's extra spaces.

    ReplyDelete
    Replies
    1. Hi as a long back i wrote this blog so do not remember exactly but please look in toPdfViewerActivity and it will help you to understand the layout and than you can examine which will not be a difficult task to you.

      Delete
    2. thanks for reply.
      i have already seen and changed all the parameters of layout but nothing happened please help me.

      Delete
    3. hi i will try to get in to it and will be back to you!!

      Delete
    4. Please revisit PdfViewerActivity, it must surly help you .

      Delete
  36. Hello, is it possible to view pdf that stored in server? So we see it online using the application instead of download the file and then view it using the application. I really need the answer for my thesis. Thank you so much for your help.

    ReplyDelete
    Replies
    1. Hi YES You can do that, firstly get a pdf file as a stream from server and save it locally to device and than access after successful download on screen.

      Delete
    2. Can we use it for corporate projects is it free to use

      Delete
    3. yeah i think so because this is all about a lib which i used in the given example.

      Delete
    4. public class TabActivity1 extends Activity {




      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.tab1);

      AssetManager assetManager = getAssets();

      Intent intent = new Intent(this, Secondpdf.class);
      intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "assets/vinayaka.pdf");
      startActivity(intent);



      InputStream stream = null;
      try {
      stream = assetManager.open("assets/vinayaka.pdf");
      } catch (IOException e) {
      // handle
      }
      finally {
      if (stream != null) {
      try {
      stream.close();
      } catch (IOException e) {}
      }
      }







      }

      }

      Is this correct or not???When im trying to run it is showing "Loading pdf" but not opening pdf file.And i kept my pdf file in assets folder.

      Delete
    5. Hello.. did you manage to solve this?
      I used: intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "file:///android_asset/CH1.pdf");


      but the Dialog does not disappear and shows continuously "Loading PDF Page"

      Delete
  37. Hello Brother.
    I downloaded the project and can not use it in Eclipse and the Android Studio.
    Do you have any outher project working for me to learn from an example?

    ReplyDelete
    Replies
    1. Please visit http://android-arsenal.com/ and look there..you will get a good learning project there for sure.

      Delete
  38. Please give me code which open pdf from assets...

    ReplyDelete
  39. Superb Tutorial Dude... #Appreciation !

    ReplyDelete
  40. June bonggok dgn yg gelap..bodoh

    ReplyDelete
  41. Exactly what i want but getting errors when i used you code in second.java though i have set build path for library the error is like

    A curly underline on zoom_in
    Zoom_out and all those resources stuff cannot be found can you help me to fix that you can make out i am new to android maybe its just a silly mistake

    ReplyDelete
  42. Hi how to load the pdf automatically in fullscreen, as of this time I need to press zoom to get it done. I would like to load it in 100% zoom level...thanks in advance

    ReplyDelete
    Replies
    1. Please have a look in related api method and try to set default as 100%

      Delete
  43. Hi, can it be bookmarked?

    ReplyDelete
  44. Hi, can it be bookmarked?

    ReplyDelete
  45. Hi,I can put PDF documents in SD Card. but still I run this project it shows white page and doesn't do anything

    ReplyDelete
  46. Hi, I followed your code but when I run the app it crashes. Please help

    ReplyDelete
  47. Hi, I followed your code but when I run the app it crashes. Please help

    ReplyDelete
  48. how can i add search option to search some strings on the content of pdf?

    ReplyDelete
  49. This is nice blog....thank you for sharing this information...this is very useful for android app development...
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies


    ReplyDelete
  50. Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every

    blog.. i am expecting more updated posts from your hands.
    Mobile App Development Company
    Mobile App Development Company in India
    Mobile App Development Companies

    ReplyDelete