Latest News

Pdf Reader App - Android Studio Tutorial

     DESCRIPTION     

This tutorial is about:
✓Create PDF app.
✓Display Specific or all pages from PDF
✓Display PDF from Assets folder.
✓Add padding between pages
✓Passwords
✓Scroll PDF pages vertically or Swipe horizontally.

     VIDEO     


     SOURCE CODE     

Step 1: Create a new project OR Open your project

Step 2: Add following library in build.gradle(Module:app) 

 implementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'

Step 3: Create Assets folder and place a pdf file in that folder.

Step 4: Code

build.gradle(Module:app)
apply plugin: 'com.android.application'android {compileSdkVersion 27defaultConfig {applicationId "com.blogspot.atifsoftwares.pdfapp"minSdkVersion 16targetSdkVersion 27versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt') , 'proguard-rules.pro'}}}dependencies {implementation fileTree(dir: 'libs' , include: ['*.jar'])implementation 'com.android.support:appcompat-v7:27.1.1'implementation 'com.android.support.constraint:constraint-layout:1.1.0'testImplementation 'junit:junit:4.12'androidTestImplementation 'com.android.support.test:runner:1.0.1'androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'//add library hereimplementation 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout 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"android:orientation="vertical"tools:context=".MainActivity"><com.github.barteksc.pdfviewer.PDFViewandroid:id="@+id/pdfView"android:layout_width="match_parent"android:layout_height="match_parent"/></LinearLayout>

MainActivity.java
package com.blogspot.devofandroid.pdfapp;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import com.github.barteksc.pdfviewer.PDFView;import com.github.barteksc.pdfviewer.util.FitPolicy;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//PDF ViewPDFView pdfView = findViewById(R.id.pdfView);pdfView.fromAsset("pdfexample.pdf").enableSwipe(true) // allows to block changing pages using swipe.swipeHorizontal(true).enableDoubletap(true).defaultPage(0).enableAnnotationRendering(false) // render annotations (such as comments , colors or forms).password(null).scrollHandle(null).enableAntialiasing(true) // improve rendering a little bit on low-res screens// spacing between pages in dp. To define spacing color , set view background.spacing(0).pageFitPolicy(FitPolicy.WIDTH).load();}}

Step 5: Run Project

Output
PDF reader app - Android Studio Tutorial

0 Response to "Pdf Reader App - Android Studio Tutorial"