簡體   English   中英

使用mupdf android庫導航到特定頁面

[英]navigating to a specific page with the mupdf android library

如何使用muPDF庫導航到特定頁面? 還是有一種方法可以使圖書館不記得我在那個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

這就是我目前打開pdf的方式。

您可以將Bundle中的頁面索引添加到您的意圖中,然后在MuPDFActivity中加載該索引,然后調用mDocView.setDisplayedViewIndex(your_index_from_bundle); 那應該做的。

像這樣:

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);

然后在MuPDFActivity中編輯onCreate,在onCreate的末尾添加以下代碼:

Intent intent = getIntent();
if(intent!=null){
    Bundle extras = intent.getExtras();
    if(extras!=null){
        int index = extras.getInt("key_page_index");
        mDocView.setDisplayedViewIndex(index);
    }
}
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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM