5

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.

Community
  • 1
  • 1
Christian Eric Paran
  • 980
  • 6
  • 27
  • 49

2 Answers2

2

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.

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
0

If you want an API, I don't think there are any free ones. I recently had to build one into an app for my employer, we ended up having a choice of 3 paid libraries, the cheapest of which was around $1K/app. If you just want to launch it in an external app, you can download a free one and launch the view intent on the file.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I think external PDF viewer apps chooses its own PDF File (Browsing the SDcard Files). I want my Application to send the Filepath/Page to View/Keyword to the PDF Viewer that I will use but I think external apps won't let me do that? – Christian Eric Paran Jan 12 '13 at 03:42
  • It ought to, send it the path in the intent. – Gabe Sechan Jan 12 '13 at 04:28