• 當前位置:首頁 > IT技術 > 移動平臺 > 正文

    AndroidPdfView一行代碼快速顯示pdf,支持線上下載與顯示
    2021-08-07 21:40:38

    一行代碼快速實現PDF的在線下載與本地預覽

    ?

    ?

    使用到的技術
    1,Okhttp下載文件
    2,pdfview顯示PDF



    下面是效果圖

    AndroidPdfView一行代碼快速顯示pdf,支持線上下載與顯示_PDFwebview

    AndroidPdfView一行代碼快速顯示pdf,支持線上下載與顯示_android_02

    AndroidPdfView一行代碼快速顯示pdf,支持線上下載與顯示_PDFwebview_03

    AndroidPdfView一行代碼快速顯示pdf,支持線上下載與顯示_PDFview_04

    ?

    ?


    代碼很簡單,可以到下載demo查看,下面只貼出重要代碼


    1,下載pdf

    OkHttpUtils.get(pdfUrl)//
                    .tag(this)//
                    .execute(new DownloadFileCallBack(Environment.getExternalStorageDirectory() +
                            "/temp", "qcl.pdf"));//保存到sd卡





    2,顯示pdf

     pdfView.fromFile(file)
                    //                .pages(0, 0, 0, 0, 0, 0) // 默認全部顯示,pages屬性可以過濾性顯示
                    .defaultPage(1)//默認展示第一頁
                    .onPageChange(this)//監聽頁面切換
                    .load();



    3,簡單的顯示下布局

    ?

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 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" />
    
        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="1/10"/>
    </FrameLayout>

    ?

    ?














    本文摘自 :https://blog.51cto.com/u

    開通會員,享受整站包年服務
    国产呦精品一区二区三区网站|久久www免费人咸|精品无码人妻一区二区|久99久热只有精品国产15|中文字幕亚洲无线码