Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF Viewer API for android [duplicate]

Tags:

java

android

pdf

Possible Duplicate:
Example of code to implement a PDF reader

Is there a Free PDF Viewer that I can use for my Application?

I am looking for a PDF Viewer that can search, highlight text, view the page that user wants, and without altering the contents of the PDF file. Just like Adobe Reader but for Android that can be implemented to a Application.

You can link me to a same question or source code.

EDIT:

I have found this question "Pdf viewer api/library for android app sample code?" but I think his looking for a Reader. this question "pdf viewer library for android" I read that to view pdf it should be Natively and the solution for that is to use External Applications.

If I use external application, I want the external application accepts PDF Filepath, Page to view, and Keyword for search programmatically but i think external application wont let me do that.

like image 509
Christian Eric Paran Avatar asked Nov 04 '22 06:11

Christian Eric Paran


1 Answers

Use Below Code for Read PDF using PDFViewer.jar library, it will solve your problem.

First.java

public class First extends ListActivity {

    String[] pdflist;
    File[] imagelist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        File images = Environment.getExternalStorageDirectory();
        imagelist = images.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return ((name.endsWith(".pdf")));
            }
        });
        pdflist = new String[imagelist.length];
        for (int i = 0; i < imagelist.length; i++) {
            pdflist[i] = imagelist[i].getName();
        }
        this.setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, pdflist));
    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String path = imagelist[(int) id].getAbsolutePath();
        openPdfIntent(path);
    }

    private void openPdfIntent(String path) {
        try {
            final Intent intent = new Intent(First.this, Second.class);
            intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Second.java

public class Second extends PdfViewerActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    public int getPreviousPageImageResource() {
        return R.drawable.left_arrow;
    }

    public int getNextPageImageResource() {
        return R.drawable.right_arrow;
    }

    public int getZoomInImageResource() {
        return R.drawable.zoom_in;
    }

    public int getZoomOutImageResource() {
        return R.drawable.zoom_out;
    }

    public int getPdfPasswordLayoutResource() {
        return R.layout.pdf_file_password;
    }

    public int getPdfPageNumberResource() {
        return R.layout.dialog_pagenumber;
    }

    public int getPdfPasswordEditField() {
        return R.id.etPassword;
    }

    public int getPdfPasswordOkButton() {
        return R.id.btOK;
    }

    public int getPdfPasswordExitButton() {
        return R.id.btExit;
    }

    public int getPdfPageNumberEditField() {
        return R.id.pagenum_edit;
    }
}

And Declared Both Activities into your manifest file.

like image 128
Dipak Keshariya Avatar answered Nov 14 '22 22:11

Dipak Keshariya