How to show pdf in read only mode In Android

faizan shoukat

As i have 3 options to show pdf file in android Like:

1)Webview 2)Action_View using Intent 3)using this library 'com.github.barteksc:android-pdf-viewer:2.8.2'

In web view there are some default options which i do not need. Using intent showing pdf file in pdf viewer or word app which gives aloot of option. And the last one,library is not working in android x.

Kindly give solution to show just only pdf in android without any share,download etc type option. Image Using Webview Image Using Intent

faizan shoukat
  1. implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'

This is the proper way of using this library

package com.example.view_pdf_by_azamkhan;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
import com.shockwave.pdfium.PdfDocument;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class PdfActivity extends AppCompatActivity implements OnPageChangeListener, OnLoadCompleteListener {


    PDFView pdfView;
    Integer pageNumber = 0;
    String pdfFileName;
    String TAG="PdfActivity";
    int position=-1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdf);
        init();
    }

    private void init(){
        pdfView= (PDFView)findViewById(R.id.pdfView);
        position = getIntent().getIntExtra("position",-1);
        displayFromSdcard();
    }

    private void displayFromSdcard() {
       //get file name
        pdfFileName = MainActivity.fileList.get(position).getName();  

        //get complete file
        pdfView.fromFile(MainActivity.fileList.get(position))
                .defaultPage(pageNumber)
                .enableSwipe(true)
                .swipeHorizontal(false)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
                .scrollHandle(new DefaultScrollHandle(this))
                .load();
    }
    @Override
    public void onPageChanged(int page, int pageCount) {
        pageNumber = page;
        setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
    }

    @Override
    public void loadComplete(int nbPages) {
        PdfDocument.Meta meta = pdfView.getDocumentMeta();
        printBookmarksTree(pdfView.getTableOfContents(), "-");

    }

    public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
        for (PdfDocument.Bookmark b : tree) {

            Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));

            if (b.hasChildren()) {
                printBookmarksTree(b.getChildren(), sep + "-");
            }
        }
    }

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How i can view pdf in browser in read only mode?

How to show custom dialog in portarit mode only in android?

How can I show(read only) xslx, pdf files in react/javascript using (.xslx or .pdf) urls?

How to show a widget only in debug mode

How secure is read-only mode for wordpress?

How to use READ ONLY transaction mode in SQLAlchemy?

How to disable read only mode in MicroStrategy 9.3

How to show read only unique id in form?

How to show Android keyboard with symbols mode by default?

Need help to show image from gallery only in portrait mode Android

Read only mode in keras

How to force djCurrencyTextBox to show currency symbol in read mode?

how to read pdf file file in android studio

How to mount casper persistent partition in "read only" mode?

How to disable Read Only mode in Azure Function App?

How to open a word document in read-only mode into SWT shell

UIPATH - how to check if an Excel file is on "Read only" mode or not

How to check the CURRENTLY OPEN excel file is open in read only mode?

How to check if a file is in read-only mode in C

How to manipulate a Word 2013 document opened in read only mode

How to show only a specific month on Android CalendarView?

How to show notification on Android Wear device only

How to show the hours only using Timepicker in android

how to show only status bar in android

Android how to show front camera (for mirror only)

Azure Function is in Read Only mode

How to show blinking text cursor/caret in a read-only div

How can I browse a network drive I have read-write access to in read-only mode?

How to remount a device in read-write mode, which is already mounted read-only?