Android Display PDF File

Source: Internet
Author: User

1. Open Source Project Address:

Https://github.com/JoanZapata/android-pdfview

2. References

 compile ‘com.joanzapata.pdfview:android-pdfview:[email protected]

3. layout file

<?xml version="1.0"encoding="Utf-8"? ><relativelayout 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"android:fitssystemwindows="true"Tools:context="zyj.com.myapplication.MainActivity"> <Com.joanzapata.pdfview.PDFView Android:id="@+id/pdfview"Android:layout_width="match_parent"Android:layout_height="match_parent"/></relativelayout>

Use

Package Zyj.com.myapplication;import Android.graphics.canvas;import android.os.bundle;import Android.support.v7.app.appcompatactivity;import Android.widget.toast;import Com.joanzapata.pdfview.PDFView; Import Com.joanzapata.pdfview.listener.ondrawlistener;import Com.joanzapata.pdfview.listener.onloadcompletelistener;import Com.joanzapata.pdfview.listener.onpagechangelistener;import Java.io.File; Public classMainactivity extends Appcompatactivity implements Onpagechangelistener, Onloadcompletelistener, Ondrawliste NER {PrivatePdfview Pdfview; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Pdfview=(Pdfview) Findviewbyid (R.id.pdfview); //read PDF from assets directoryDisplayfromassets ("bao.pdf"); //reading a PDF from a fileDisplayfromfile (NewFile ("FileName")); }    Private voiddisplayfromassets (String assetfilename) {pdfview.fromasset (assetfilename)//Set the PDF file address. Defaultpage (6)//set default to show page 1th. Onpagechange ( This)//set page Turn monitoring. OnLoad ( This)//Set Load monitoring. OnDraw ( This)//Drawing Monitoring. Showminimap (false)//when a PDF is zoomed in, does it generate a small map in the upper-right corner of the screen. swipevertical (false)//whether the page of a PDF document is a vertical page, the default is to scroll left and right. Enableswipe (true)//whether to allow page flipping, the default is to allow page flipping//. Pages (2, 3, 4, 5)//filter out 2, 3, 4, 5. Load (); }    Private voiddisplayfromfile (file file) {pdfview.fromfile (file)//Set the PDF file address. Defaultpage (6)//set default to show page 1th. Onpagechange ( This)//set page Turn monitoring. OnLoad ( This)//Set Load monitoring. OnDraw ( This)//Drawing Monitoring. Showminimap (false)//when a PDF is zoomed in, does it generate a small map in the upper-right corner of the screen. swipevertical (false)//whether the page of a PDF document is a vertical page, the default is to scroll left and right. Enableswipe (true)//whether to allow page flipping, the default is to allow//. Pages (2, 3, 4, 5)//filter out 2, 3, 4, 5. Load (); }    /** * Page Turn callback * @param page * @param pagecount*/@Override Public voidOnpagechanged (intPageintPageCount) {Toast.maketext (mainactivity). This,"page="+ page +"pagecount="+PageCount, Toast.length_short). Show (); }    /** * Load Complete callback * @param nbpages total pages*/@Override Public voidLoadComplete (intnbpages) {Toast.maketext (mainactivity). This,"Load Complete"+nbpages, Toast.length_short). Show (); } @Override Public voidOnlayerdrawn (Canvas canvas,floatPageWidth,floatPageHeight,intdisplayedpage) {       //Toast.maketext (mainactivity.this, "pagewidth=" + pagewidth + "//pageheight= "+ pageheight +" displayedpage= "+ Displayedpage, Toast.length_short). Show ();    }}

4. Project Address (Android Studio Environment)

http://download.csdn.net/detail/yanzi2015/9341525

Android Display PDF File

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.