Kotlin PDF Viewer Library Example – Coding Shiksha

Kotlin PDF Viewer Library Example – Coding Shiksha

Welcome folks I am back with another blog post. Today in this post we will be looking at a library which allows you to embed PDF Documents in Kotlin Application. The library name is PdfView-Android. You can download the library from here:

  1. Download

Features

  1. It can handle big files to embed in Android Application
  2. It is based on ImageView Element in Android
  3. It gives you ultimate performance in rendering complex and big size PDF Documents.
READ  Kotlin Date time picker using JRDateTimePicker

 

Demo

 

 

How to Use

 

In order to use this library you need a PDF File on the system. Then you can write this line of code to include it through this library and display the file in app.

READ  Kotlin (Android) Send SMTP Email with Awesome MailDroid Library [NEW] - Coding Shiksha

 

findViewById<PDFView>(R.id.activityMainPdfView).fromAsset("paper.pdf").show()

 

Add to your project:

repositories {
        <...>
        jcenter()
    }

 

Add gradle dependency:

 

implementation "com.pdfview:pdfview-android:1.0.0"

Full Example Code

 

  1. Layout File:

 

activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

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

</android.support.constraint.ConstraintLayout>

 

READ  Kotlin(Android) Typing Indicator or Wait Progress Animation - Coding Shiksha

2) Java Code:

 

MainActivity.kt

 

package com.pdfview_sample.pdfview

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.pdfview.PDFView

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<PDFView>(R.id.activityMainPdfView).fromAsset("great-expectations.pdf").show()
//        findViewById<PDFView>(R.id.activityMainPdfView).fromAsset("paper.pdf").show()
    }
}

Leave a Reply

Close Menu

Indian Desi Tools - Ultimate Tools Website

Demo Description


This will close in 20 seconds