import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.RectF; import android.util.Log; import java.util.LinkedList; import com.artifex.mupdfdemo.MuPDFCore; import com.artifex.mupdfdemo.OutlineActivityData; import com.artifex.mupdfdemo.Page; import com.artifex.mupdfdemo.TextWord; public class MuPDFReader { private final static String TAG = "MuPDFReader"; private MuPDFCore mCore; private Page mCurrentPage; private int mCurrentPageNumber; private DocumentListener mListener; public MuPDFReader(String path) { try { mCore = new MuPDFCore(path); mCurrentPageNumber = 0; mCurrentPage = mCore.getPage(0); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } public int getPageCount() { return mCore.countPages(); } public void setCurrentPage(int pageNumber) { if (pageNumber < 0 || pageNumber >= mCore.countPages()) { return; } mCurrentPageNumber = pageNumber; mCurrentPage = mCore.getPage(pageNumber); if (mListener != null) { mListener.onPageChanged(pageNumber); } } public int getCurrentPageNumber() { return mCurrentPageNumber; } public void setDocumentListener(DocumentListener listener) { mListener = listener; } public void goToPreviousPage() { if (mCurrentPageNumber > 0) { mCurrentPageNumber--; mCurrentPage = mCore.getPage(mCurrentPageNumber); if (mListener != null) { mListener.onPageChanged(mCurrentPageNumber); } } } public void goToNextPage() { if (mCurrentPageNumber < mCore.countPages() - 1) { mCurrentPageNumber++; mCurrentPage = mCore.getPage(mCurrentPageNumber); if (mListener != null) { mListener.onPageChanged(mCurrentPageNumber); } } } public Bitmap getPageBitmap(int width, int height) { return mCurrentPage.getBitmap(width, height); } public LinkedList<OutlineActivityData> getOutlines() { LinkedList<OutlineActivityData> data = new LinkedList<OutlineActivityData>(); OutlineActivityData root = new OutlineActivityData(null, -1); root.children = mCore.getOutline(); data.add(root); return data; } public LinkedList<TextWord> getTextWords() { return mCurrentPage.getText(); } public RectF getPageBounds(int width, int height) { return mCurrentPage.getBounds(width, height); } public void drawBackground(Bitmap bm, int pageW, int pageH, int patchX, int patchY, int patchW, int patchH) { mCurrentPage.drawBackground(bm, pageW, pageH, patchX, patchY, patchW, patchH); } public void drawPage(Bitmap bm, int pageW, int pageH, int patchX, int patchY, int patchW, int patchH) { mCurrentPage.draw(bm, pageW, pageH, patchX, patchY, patchW, patchH, Color.BLACK, Color.WHITE); } public void addAnnotation(float x, float y, float w, float h, int color) { mCurrentPage.addAn
标签:mupdf,mCurrentPageNumber,翻页,int,mCurrentPage,mCore,import,java,public From: https://www.cnblogs.com/chenKnowledgeConllection/p/17092436.html