DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.18k stars 1.91k forks source link

How can I open pdf file inside my app after implementation of pdf viewer or should I need to import any module #905

Open nayasapnaa opened 4 years ago

nayasapnaa commented 4 years ago

Please help me I have a download button and read button. After download the read button will work. But when I click read it's showing to chose app to read pdf.

I want to read pdf inside my app. Please help me how can I do.

Waiting for your reply

Get rigid of the problem since May 😕😕

1stmetro commented 4 years ago

You need to add pdfview to your app and then follow the example to load the pdf directly from within your app.

Add to build.gradle:

implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'

or if you want to use more stable version:

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

and follow the example.

https://github.com/barteksc/AndroidPdfViewer

JantuDeb commented 4 years ago

you have to pass the file name and the path of directory to open the pdf..

` public class OpenPdf extends AppCompatActivity { public PDFView pdfView; private String pdfName = ""; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentVieww(R.layout.activity_pdf_view); pdfView = findViewById(R.id.pdfView); if(getIntent().getExtras() != null){ pdfName = getIntent().getExtras().getString("pdf_name"); } openPdf(pdfName); }

private void openPdf(String pdfName) {
    try {
        final File file = getFileStreamPath(pdfName);
        if (file != null) {
            Log.e("file", "file" + file.getAbsolutePath());

            pdfView.fromFile(file).enableSwipe(true)
                    .scrollHandle(new DefaultScrollHandle(this))

                    .swipeHorizontal(false).onError(new OnErrorListener() {
                @Override
                public void onError(Throwable t) {
                    Log.e("file", "file" + t.toString());
                    try {
                        if (file.exists())
                            file.delete();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).enableAntialiasing(true).spacing(10).pageFitPolicy(FitPolicy.WIDTH).load();

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

} `

nayasapnaa commented 4 years ago

Will you send me your contact details or email... To check my file.... I have implemented but can't solve the problem

JantuDeb commented 4 years ago

You can post it here...

Will you send me your contact details or email... To check my file.... I have implemented but can't solve the problem

nayasapnaa commented 4 years ago

Ok On Mon, 15 Jun, 2020, 12:52 PM JD, notifications@github.com wrote:

You can post it here...

Will you send me your contact details or email... To check my file.... I have implemented but can't solve the problem

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/barteksc/AndroidPdfViewer/issues/905#issuecomment-643951610, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKM72RW5GHEW5RQNWULOVYTRWXD2DANCNFSM4N5IPRDA .