【问题标题】:navigating to a specific page with the mupdf android library使用 mupdf android 库导航到特定页面
【发布时间】:2014-04-08 20:24:17
【问题描述】:

如何使用 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 的方式。

【问题讨论】:

标签: android pdf mupdf


【解决方案1】:

您可以将 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);
    }
}

【讨论】:

  • 尝试后:MuPDFReaderView bla = new MuPDFReaderView (activity); bla.setDisplayViewIndex;如果我使用高于 -1 public void setDisplayedViewIndex(int i){ if(0
  • @LubošStaráček 请帮帮我stackoverflow.com/questions/24508322/…
  • 这会产生空指针异常,无论如何方法都是正确的。
【解决方案2】:
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);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 2020-12-25
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    相关资源
    最近更新 更多