2

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.

David
  • 105
  • 1
  • 9
  • can you please help me regarding these questions http://stackoverflow.com/questions/24508322/fatal-error-fitz-h-no-such-file-or-directory-in-mupdf-library – Qadir Hussain Jul 04 '14 at 10:02

2 Answers2

3

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);
    }
}
  • after trying this: MuPDFReaderView bla = new MuPDFReaderView (activity); bla.setDisplayViewIndex; it started giving me a null pointer exception on this line inside readerView if i use any value above -1 public void setDisplayedViewIndex(int i){ if(0<=i && i < mAdapter.getCount()){ is this because I'm running it too soon before the document is loaded by muPDF? When should i be running setDisplayedViewIndex? – David Mar 06 '14 at 10:57
  • @LubošStaráček please help me http://stackoverflow.com/questions/24508322/fatal-error-fitz-h-no-such-file-or-directory-in-mupdf-library – Qadir Hussain Jul 04 '14 at 10:02
  • This produces a Null Pointer Exception,anyway the approach is correct. – techno Nov 20 '15 at 06:19
0
package com.artifex.mupdf;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.util.Log;

public class MuPDFPageView extends PageView {
    private final MuPDFCore mCore;

    public MuPDFPageView(Context c, MuPDFCore core, Point parentSize) {
        super(c, parentSize);
        mCore = core;
    }

    public String hitLinkPage(float x, float y) {
        // Since link highlighting was implemented, the super class
        // PageView has had sufficient information to be able to
        // perform this method directly. Making that change would
        // make MuPDFCore.hitLinkPage superfluous.
        float scale = mSourceScale * getWidth() / mSize.x ;


        float docRelX = (x - getLeft()) / scale;
        float docRelY = (y - getTop()) / scale;
           Log.d("Page Number", "hitLinkPage with page = " + mCore.hitLinkPage(mPageNumber, docRelX, docRelY));
        return mCore.hitLinkPage(mPageNumber, docRelX, docRelY);
    }

    @Override
    protected void drawPage(Bitmap bm, int sizeX, int sizeY, int patchX,
            int patchY, int patchWidth, int patchHeight) {
        mCore.drawPage(mPageNumber, bm, sizeX, sizeY, patchX, patchY,
                patchWidth, patchHeight);
    }

    @Override
    protected LinkInfo[] getLinkInfo() {
        return mCore.getPageLinks(mPageNumber);
    }
}
prasad thangavel
  • 173
  • 1
  • 2
  • 11