Android displays PDF files and androidpdf files

Source: Internet
Author: User

Android displays PDF files and androidpdf files

1. Open-Source Project address:

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

 

2. Reference

compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'

 

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.pdf view. lateral view; import com.joanzapata.pdf view. listener. onDrawListener; import com.joanzapata.pdf view. listener. onLoadCompleteListener; import com.joanzapata.pdf view. listener. onPageChangeListener; import java. io. file; public class MainActivity extends AppCompatActivity implements OnPageChangeListener, OnLoadCompleteListener, OnDrawListener {private lateral view; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); lateral View = (lateral View) findViewById (r.id1_view); // read the pdf displayFromAssets ("baosets") from the assets Directory "); // read pdf displayFromFile (new File ("fileName") from the File;} private void displayFromAssets (String assetFileName) {lateral view. fromAsset (assetFileName) // sets the PDF file address. defaultPage (6) // set to display page 1st by default. onPageChange (this) // sets the page flip listener. onLoad (this) // sets the load listener. onDraw (this) // graph monitoring. showMinimap (false) // specifies whether to generate a small map in the upper-right corner of the screen when the pdf file is enlarged. swipeVertical (false) // whether the page flip of the pdf document is vertical page flip. By default, the page flip is left and right. enableSwipe (true) // whether to allow page turning. By default, page turning is allowed //. pages (2, 3, 4, 5) // filter out 2, 3, 4, 5. load ();} private void displayFromFile (File file) {lateral view. fromFile (file) // sets the PDF file address. defaultPage (6) // set to display page 1st by default. onPageChange (this) // sets the page flip listener. onLoad (this) // sets the load listener. onDraw (this) // graph monitoring. showMinimap (false) // specifies whether to generate a small map in the upper-right corner of the screen when the pdf file is enlarged. swipeVertical (false) // whether the page flip of the pdf document is vertical page flip. By default, the page flip is left and right. enableSwipe (true) // whether to allow page flip. The default value is to allow page flip //. pages (2, 3, 4, 5) // filter out 2, 3, 4, 5. load ();}/*** page flip callback * @ param page * @ param pageCount */@ Override public void onPageChanged (int page, int pageCount) {Toast. makeText (MainActivity. this, "page =" + page + "pageCount =" + pageCount, Toast. LENGTH_SHORT ). show ();}/*** callback for loading completion * @ param nbPages total page number */@ Override public void loadComplete (int nbPages) {Toast. makeText (MainActivity. this, "loaded" + nbPages, Toast. LENGTH_SHORT ). show () ;}@ Override public void onLayerDrawn (Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {// 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

 

Related Article

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.