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
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
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
Can i add my button to view second?
ReplyDeleteyes you can customize yours own way.
DeleteCan I add text selection event?
ReplyDeleteYes 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 :)
DeleteHi when I run this project it shows white page and doesn't do anything. what's the reason?
ReplyDeletethank you
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.
Deleteu must have not declared your second class in the manifest
DeleteI want to put pdf file in res/raw folder.
ReplyDeletewhich part of the code should be changed?
please say it clearly ,I'm new developer in android
Please see the function/method
Deleteprivate 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.
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.
ReplyDeleteAny Idea how many languages are supported ?
--
Rahul Pundhir
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.
DeleteWhen I click on PDf file
ReplyDeleteI 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
i seen the logs please try==>To fix this problem you need to:
DeleteCreate 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
Hi,
ReplyDeleteI 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
Hi deep can i have some debug logs that it will be better to know where the problem came?
DeleteThis comment has been removed by the author.
ReplyDelete10-10 14:37:50.421: E/PDFVIEWER(319): null
ReplyDelete10-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'
hi
ReplyDeleteI 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
You need to go for Gestures. You will have callback methods like
DeleteonScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY)
onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY)
please try with them!!
Hello, how can I get action bar in this Second Activity which extends PdfViewerActivity. Please guide.
ReplyDeleteHi 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
ReplyDeleteHi,
DeleteThnks 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.
PdfViewerActivity activity can extend SherlockActivity and use some corresponding interfaces and you can proceed with this direction.
DeleteHello sir,
ReplyDeleteCan you tell me how to get the current page number of pdf .
Hi Saurabh please investigate api of the library, there are some method regarding the page number and related stuff.
Deletehi sir,
ReplyDeletecan 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;
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!!
DeleteHi sir,
ReplyDeleteI 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)
Right Click on your Project then
DeleteGoto 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
Not able to view pdf file. blank screen
ReplyDelete01-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
hey how to pdf open using assets folder
ReplyDeleteHello Jitesh..
ReplyDeleteVery 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..!!
Hi again..
DeleteThe 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..:)
sorry that i did not seen the problem when you send the message but if it is solved than it is great to know!!
Deletehi Priya..
DeleteTo display AndroidPdfViewer in KitKat Which Permissions You are Giving on Manifest File..Please Help Me.
hey i want to open using assets folder how can i open ?
ReplyDeletehi..
ReplyDeletei 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..
how can i access a method used in the pdfviewerlibrary in second.java?
ReplyDeleteplease have a look at PdfViewerActivity documentation what you can do is extend the PdfViewerActivity and use them or override them according to yours use!!
DeleteHello,
ReplyDeleteIs 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! :)
To reply to my own question, this library does not allow rendering multiple pages simultaneously.
DeleteUsed muPDF. Much faster, much simpler.
Many thanks Atul for the finding , i will also try with that, can you please give me the link of that library!!
DeleteHi Jitesh,
ReplyDeleteI 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.
Thank you for nice tutorial @Jitesh (y)
ReplyDeleteHi,
ReplyDeleteIts 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?
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
ReplyDeleteGetting Error on this line
ReplyDeletepdflist = new String[imagelist.length];
at com.example.pdfview.MainActivity.onCreate(MainActivity.java:32)
can we use Pdf Viewer In Fragment If Yes ..Then How .?..I m Following Ur Blog
ReplyDeletei dont Want Go From Here With Upset Mood ... plzzz
mail me , i will tell you
Deletemail me , i will tell you
Deleteit shows only Loading PDF Pages.... Please help
ReplyDeleteI'm getting my pDF file opened in an unreadable form.(Something like an inverted way)
ReplyDeleteunreadable form.?? please check the logs!!
DeleteHi!! Could be possible to add pinch-zoom function in this activity, instead of using the existing but uneasy zoom buttons? Thanks
ReplyDeleteHow do I modify PdfViewerActivity, where methods are, if it is derivated from an external source?
DeleteHi 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 .
DeleteHi 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 .
ReplyDeleteThis comment has been removed by the author.
ReplyDeletehi can i use url instead of filepath in thid code? if yes how. becz when i m using url it is not working.
ReplyDeleteplease check in the lib code /api that we can use a url or not!!
Deletecheckd not working
Deletehello 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.
ReplyDeleteHi 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.
Deletethanks for reply.
Deletei have already seen and changed all the parameters of layout but nothing happened please help me.
hi i will try to get in to it and will be back to you!!
Deleteok thank you.
Deletewill wait for your reply.
DeletePlease revisit PdfViewerActivity, it must surly help you .
DeleteHello, 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.
ReplyDeleteHi 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.
DeleteCan we use it for corporate projects is it free to use
Deleteyeah i think so because this is all about a lib which i used in the given example.
Deletepublic class TabActivity1 extends Activity {
Delete@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.
Hello.. did you manage to solve this?
DeleteI used: intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "file:///android_asset/CH1.pdf");
but the Dialog does not disappear and shows continuously "Loading PDF Page"
Hello Brother.
ReplyDeleteI 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?
Please visit http://android-arsenal.com/ and look there..you will get a good learning project there for sure.
DeletePlease give me code which open pdf from assets...
ReplyDeleteSuperb Tutorial Dude... #Appreciation !
ReplyDeleteJune bonggok dgn yg gelap..bodoh
ReplyDeleteExactly 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
ReplyDeleteA 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
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
ReplyDeletePlease have a look in related api method and try to set default as 100%
DeleteHi, can it be bookmarked?
ReplyDeleteHi, can it be bookmarked?
ReplyDeleteHi,I can put PDF documents in SD Card. but still I run this project it shows white page and doesn't do anything
ReplyDeleteHi, I followed your code but when I run the app it crashes. Please help
ReplyDeleteHi, I followed your code but when I run the app it crashes. Please help
ReplyDeletehow can i add search option to search some strings on the content of pdf?
ReplyDeleteThis is nice blog....thank you for sharing this information...this is very useful for android app development...
ReplyDeleteMobile App Development Company
Android app Development Company
ios app development Company
Mobile App Development Companies
Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every
ReplyDeleteblog.. i am expecting more updated posts from your hands.
Mobile App Development Company
Mobile App Development Company in India
Mobile App Development Companies