Search code examples
androidpdfmupdf

navigating to a specific page with the mupdf android library


How would I go about navigating to a specific page with the muPDF library? Or is there a way to make the library not remember which page I was last on in that pdf?

Uri uri = Uri.parse(path);
Intent intent = new Intent(MainActivity.getContext(), MuPDFActivity.class)
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
c.startActivity(intent);
//c is context

This is how i'm currently opening pdfs.


Solution

  • You can add page index in Bundle into your intent, load that index in MuPDFActivity thereafter and call mDocView.setDisplayedViewIndex(your_index_from_bundle); That should do the job.

    Something like that:

    Uri uri = Uri.parse(path);
    Intent intent = new Intent(MainActivity.getContext(), MuPDFActivity.class)
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(uri);
    Bundle extras = intent.getExtras();
    extras.putInt("key_page_index", 10);
    c.startActivity(intent);
    

    Then edit onCreate in MuPDFActivity, add this code at the end of the onCreate:

    Intent intent = getIntent();
    if(intent!=null){
        Bundle extras = intent.getExtras();
        if(extras!=null){
            int index = extras.getInt("key_page_index");
            mDocView.setDisplayedViewIndex(index);
        }
    }