Android PDFView is a library which provides a fast PDFView component for Android, with animations, gestures, and zoom.
the reference is taken from PDF View.
We just need to use com.joanzapata.pdfview.PDFView at xml layout as follows
<com.joanzapata.pdfview.PDFView
android:id="@+id/pdfview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
and than can be used in main activity as follows
pdfView.fromAsset(pdfName)
.pages(0, 2, 1, 3, 3, 3)
.defaultPage(1)
.showMinimap(false)
.enableSwipe(true)
.onDraw(onDrawListener)
.onLoad(onLoadCompleteListener)
.onPageChange(onPageChangeListener)
.load();
for a reference here is a full code of
activity_main.xml is as follows
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.joanzapata.pdfview.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
while PDFView can be used in PDFViewActivity as follows
import com.joanzapata.pdfview.PDFView;
import com.joanzapata.pdfview.listener.OnPageChangeListener;
import android.app.Activity;
import android.os.Bundle;
public class PDFViewActivity extends Activity implements OnPageChangeListener {
public static final String SAMPLE_FILE = "sample.pdf";
public static final String ABOUT_FILE = "about.pdf";
PDFView pdfView;
String pdfName = ABOUT_FILE;
Integer pageNumber = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pdfView = (PDFView) findViewById(R.id.pdfView);
display(pdfName, false);
}
private void display(String assetFileName, boolean jumpToFirstPage) {
if (jumpToFirstPage)
pageNumber = 1;
setTitle(pdfName = assetFileName);
pdfView.fromAsset(assetFileName).defaultPage(pageNumber)
.onPageChange(this).load();
}
@Override
public void onPageChanged(int page, int pageCount) {
pageNumber = page;
setTitle(pdfName = pageNumber+"");
}
}
the reference is taken from PDF View.
We just need to use com.joanzapata.pdfview.PDFView at xml layout as follows
<com.joanzapata.pdfview.PDFView
android:id="@+id/pdfview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
and than can be used in main activity as follows
pdfView.fromAsset(pdfName)
.pages(0, 2, 1, 3, 3, 3)
.defaultPage(1)
.showMinimap(false)
.enableSwipe(true)
.onDraw(onDrawListener)
.onLoad(onLoadCompleteListener)
.onPageChange(onPageChangeListener)
.load();
for a reference here is a full code of
activity_main.xml is as follows
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.joanzapata.pdfview.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
while PDFView can be used in PDFViewActivity as follows
import com.joanzapata.pdfview.PDFView;
import com.joanzapata.pdfview.listener.OnPageChangeListener;
import android.app.Activity;
import android.os.Bundle;
public class PDFViewActivity extends Activity implements OnPageChangeListener {
public static final String SAMPLE_FILE = "sample.pdf";
public static final String ABOUT_FILE = "about.pdf";
PDFView pdfView;
String pdfName = ABOUT_FILE;
Integer pageNumber = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pdfView = (PDFView) findViewById(R.id.pdfView);
display(pdfName, false);
}
private void display(String assetFileName, boolean jumpToFirstPage) {
if (jumpToFirstPage)
pageNumber = 1;
setTitle(pdfName = assetFileName);
pdfView.fromAsset(assetFileName).defaultPage(pageNumber)
.onPageChange(this).load();
}
@Override
public void onPageChanged(int page, int pageCount) {
pageNumber = page;
setTitle(pdfName = pageNumber+"");
}
}
make sure that you have sample pdf files in Asset folder of yours project.
the library code can be downloaded from https://github.com/JoanZapata/android-pdfview and than PDFViewActivity can be used simply as in above given example.
Download code from Demo PDF Activity
Download code from Demo PDF Activity
thankssssssssssss its wrkinggggggggggggg
ReplyDeletethank uuuuuuuuuuuuuuuuuuuuuuu
ReplyDeleteHi jit
ReplyDeleteCanu like to share how to display PDF from server..although I did but throwing
Me error of PDF document size is 0
Kindly assist
Thanks
Please search an example at github and https://android-arsenal.com/ as personally i did not got chance to work on that part :)
DeleteThis comment has been removed by the author.
ReplyDeleteHi Jitesh ,
ReplyDeleteThanks your code working good i want to swipe vertically for page navigation inspect of horizontal swiping .
Kindly assist
Thanks
Hi Jitesh ,
ReplyDeleteThanks your code working good i want to swipe vertically for page navigation inspect of horizontal swiping .
Kindly assist
Thanks
Hi Jitesh,
ReplyDeleteI try to give another pdf in asset folder instead of about.pdf but its not working or on emulator its remain as it is after Run as its not change.
please give me solution.
Kindly assist
Thanks
hi i am not sure why the another pdf is not working while first one is running , so please can you give me some logs that i can look in to them.
DeleteHi,
ReplyDeletePlease guide me how can I show a pdf file from SD card (not assets).
This comment has been removed by the author.
DeletepdfView.fromFile(new File("pathtofile"))...
DeleteThis comment has been removed by the author.
ReplyDeleteDear Jitesh,
ReplyDeleteCan you send me your demo pdf activity code as I am not able to download it from the site? Can send to cliffordng888@live.com
Thanks a lot
Dear Jitesh,
ReplyDeleteI am new to Android development and is doing an apps to view pdf within the apps. Your help is much appreciated if you could send me your demo code. Thanks
How to programatically change the page using this library ?
ReplyDeleteHow did you include the library as a folder in build path ?
ReplyDeletehi,its working but images are not loading :(
ReplyDeleteThis is nice blog and very useful to android application.....
ReplyDeleteMobile App Development Company
Android app Development Company
ios app development Company
Mobile App Development Companies
iOS App Development Services in EUROPE,iPhone App Development Services EUROPE,Android App Development Services EUROPE,Mobile Application Development Services EUROPE
ReplyDeletei Digital Academy ensures that each of you gain maximum knowledge based on current web trends, hence we employ trainers who are working in MNC. Making you ready for job and assisting you to get a job in Angularjs is our priority. Our Angularjs trainer focus on each and every detail to make sure you gain the best knowledge in terms of Angularjs . Your trainers with extensive experience in Angularjs and connections will refer you to companies that are looking for fresh talent after successful web development course completion.
ReplyDeleteHi, nice information is given in this blog. Thanks for sharing this type of information, it is so useful for me. nice work keep it up
ReplyDeleteApp Development Company in Hyderabad