JustOpenPdf

Quite simple Android library for PDF preview

License

License

Categories

Categories

PDF Data OpenPDF
GroupId

GroupId

ru.blizzed
ArtifactId

ArtifactId

justopenpdf
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

aar
Description

Description

JustOpenPdf
Quite simple Android library for PDF preview
Project URL

Project URL

https://github.com/BlizzedRu/JustOpenPdf
Source Code Management

Source Code Management

https://github.com/BlizzedRu/JustOpenPdf

Download justopenpdf

How to add to project

<!-- https://jarcasting.com/artifacts/ru.blizzed/justopenpdf/ -->
<dependency>
    <groupId>ru.blizzed</groupId>
    <artifactId>justopenpdf</artifactId>
    <version>1.0.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/ru.blizzed/justopenpdf/
implementation 'ru.blizzed:justopenpdf:1.0.0'
// https://jarcasting.com/artifacts/ru.blizzed/justopenpdf/
implementation ("ru.blizzed:justopenpdf:1.0.0")
'ru.blizzed:justopenpdf:aar:1.0.0'
<dependency org="ru.blizzed" name="justopenpdf" rev="1.0.0">
  <artifact name="justopenpdf" type="aar" />
</dependency>
@Grapes(
@Grab(group='ru.blizzed', module='justopenpdf', version='1.0.0')
)
libraryDependencies += "ru.blizzed" % "justopenpdf" % "1.0.0"
[ru.blizzed/justopenpdf "1.0.0"]

Dependencies

compile (7)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.3.31
androidx.appcompat » appcompat jar 1.0.2
androidx.core » core-ktx jar 1.0.2
com.otaliastudios : zoomlayout jar 1.5.1
io.reactivex.rxjava2 : rxjava jar 2.2.9
io.reactivex.rxjava2 : rxandroid jar 2.1.1
org.jetbrains.kotlin : kotlin-android-extensions-runtime jar 1.3.31

Project Modules

There are no modules declared in this project.

JustOpenPdf

Quite simple Android library for PDF preview

Are you looking for a simple solution to open PDF but all options don't suit you for different reasons?

Here JustOpenPdf is!

  • It doesn't bloat out your apk size (really lightweight)
  • It's under Apache License 2.0 that gives you a lot of freedom
  • It's based on ZoomLayout so you get a very customizable solution
  • It doesn't drag third-party libraries for PDF rendering – just uses built-in Android PdfRenderer
  • Min SDK – 21 Lollipop

Installing

Gradle

In your build.gradle file inside the dependencies section

  • Gradle 3.0 and above
dependencies {
   ...
   implementation 'ru.blizzed:justopenpdf:1.0.0'
}
  • Below 3.0
dependencies {
    ...
    compile 'ru.blizzed:justopenpdf:1.0.0'
}

Usage

Just include PdfView in your layout:

    <ru.blizzed.justopenpdf.PdfView
            android:id="@+id/pdfView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

Then in your Activity, Fragment, ViewController, etc use the following code:

    val pdfView = findViewById<PdfView>(R.id.pdfView)
    
    // With file path
    pdfView.openPdf("Path to the loaded PDF file.")
    
    // With file
    pdfView.openPdf(pdfFile)

If you want to listen to events of rendering process you can pass eventListener param to openPdf method.

    pdfView.openPdf(pdfFile) { event ->
        when (event) {
            is PdfRenderEvent.Processing -> {
                // Show progress bar
            }
            is PdfRenderEvent.Error -> {
                // Show rendering error
            }
            is PdfRenderEvent.Completed -> {
                // Hide progress bar and show PdfView
            }
        }
    }

Customization

You can customize page view by setting app:pageLayoutRes flag with your custom page layout that must contain ImageView.

Note that this attribute works in pair with app:pageLayoutImageViewId that points on target ImageView in layout. If it is not set @id/page_target_image will be used.

For more customization you can also extend PdfView and get access to onPageRendered(pageIndex: Int, bitmap: Bitmap) and onPageInflated(pageIndex: Int, pageView: View) callback methods where you can modify result bitmap or inflated view of the page at specified position.

Since this view is based on ZoomLayout you can use all its features. Read more about ZoomLayout on author's GitHub.

Warning

This library is not well optimized. PDF file renders entirely, all pages at once. So you can encounter memory troubles if you will try to open PDF with a big amount of pages. A size of each bitmap depends on container's size. With increasing of screen resolution a memory consumption also increases. You can affect on bitmaps sizes using app:renderResolutionFactor attribute. The default factor is 1 (it means that bitmap size will coincide with the size of PdfView container). I did research about this topic and I found out that up to 15 pages on device with FullHD screen are still good and better in comparison with WebView with the opened Google Doc Previewer.

TODOs

  • Support of double tap to zoom
  • Add current page listener for updating page counter
  • Dynamic rendering (not all pages at once) and moving to RecyclerView

License

Copyright (c) 2019 BlizzedRu (Ivan Vlasov)

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.

Versions

Version
1.0.0
0.1.0