Coder Social home page Coder Social logo

wdeo3601 / pdfview Goto Github PK

View Code? Open in Web Editor NEW
61.0 2.0 12.0 7.66 MB

安卓PDF查看器,自定义View实现。支持添加水印、三级缓存、页面预加载,缩放查看高清。

License: Apache License 2.0

Kotlin 91.35% Java 8.65%
pdfview android android-pdfview

pdfview's Introduction

PDFView

一个安卓平台的 PDF 查看器,支持滑动、缩放、三级缓存、放大展示高清图、支持一些功能配置。

  • 支持滑动、缩放、缩放后的滑动、缩放后的平移
  • 支持放大后查看高清 PDF 页
  • 支持设置预加载 PDF 页的个数,有效避免 OOM
  • 使用线程池 + Handler ,异步处理 PDF 转换 Bitmap 的相关操作
  • 使用 LruCache、DiskLruCache 缓存转换过的 PDF 页的 Bitmap
  • 支持从本地打开 PDF 文件、打开网络 PDF 文件
  • 支持为文档添加水印

使用系统自带的 PdfRenderer 来处理的 pdf 原始文件渲染,最低支持安卓5.0

效果图

正常滑动 放大后滑动 放大后平移

使用

依赖引入

implementation 'com.wdeo3601:pdf-view:1.0.4'

写 xml

    <com.wdeo3601.pdfview.PDFView
        android:id="@+id/pdf_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

代码中使用

// 设置当前显示页的前后缓存个数,效果类似 ViewPager 的这个属性
pdfView.setOffscreenPageLimit(2)

// 是否支持缩放
pdfView.isCanZoom(true)

// 设置最大缩放倍数,最大支持20倍
pdfView.setMaxScale(10f)

// 添加水印
pdfView.setWatermark(R.drawable.ic_default_watermark)

// 设置当前页变化的回调监听
pdfView.setOnPageChangedListener(object : PDFView.OnPageChangedListener {
    @SuppressLint("SetTextI18n")
    override fun onPageChanged(currentPageIndex: Int, totalPageCount: Int) {
        // show current page number
    }
})

// 从本地文件打开 pdf
pdfView.showPdfFromPath(filePath)
// 从网络打开 pdf
//pdfView.showPdfFromUrl("https://github.com/wdeo3601/PDFView/raw/master/sample.pdf")

查看更多

7天1000行代码从零开发一个 Android PDF 查看器

License

Copyright 2020 wdeo3601

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

pdfview's People

Contributors

wdeo3601 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pdfview's Issues

手指按下就重绘

这里是不是得设置一个阈值,要不然手指按下的时候,就进行重绘了,存在体验和性能上的问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.