PdfViewer是一款属性和接口全面的安卓电子书插件
地址:https://github.com/barteksc/AndroidPdfViewer
依赖:implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
<com.github.barteksc.pdfviewer.PDFView android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent"/>
pdfView.fromUri(Uri) or pdfView.fromFile(File) or pdfView.fromBytes(byte[]) or pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams or pdfView.fromSource(DocumentSource) or pdfView.fromAsset(String) .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default .enableSwipe(true) // allows to block changing pages using swipe .swipeHorizontal(false) .enableDoubletap(true) .defaultPage(0) // allows to draw something on the current page, usually visible in the middle of the screen .onDraw(onDrawListener) // allows to draw something on all pages, separately for every page. Called only for visible pages .onDrawAll(onDrawListener) .onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered .onPageChange(onPageChangeListener) .onPageScroll(onPageScrollListener) .onError(onErrorListener) .onPageError(onPageErrorListener) .onRender(onRenderListener) // called after document is rendered for the first time // called on single tap, return true if handled, false to toggle scroll handle visibility .onTap(onTapListener) .onLongPress(onLongPressListener) .enableAnnotationRendering(false) // render annotations (such as comments, colors or forms) .password(null) .scrollHandle(null) .enableAntialiasing(true) // improve rendering a little bit on low-res screens // spacing between pages in dp. To define spacing color, set view background .spacing(0) .autoSpacing(false) // add dynamic spacing to fit each page on its own on the screen .linkHandler(DefaultLinkHandler) .pageFitPolicy(FitPolicy.WIDTH) // mode to fit pages in the view .fitEachPage(false) // fit each page to the view, else smaller pages are scaled relative to largest page. .pageSnap(false) // snap pages to screen boundaries .pageFling(false) // make a fling change only a single page like ViewPager .nightMode(false) // toggle night mode .load();
推荐使用:
pdfView.fromFile(new File(filePath)) .defaultPage(0) .enableAntialiasing(true) .enableDoubletap(false) .onLoad(new onl oadCompleteListener() { @Override public void loadComplete(int nbPages) { Log.d(TAG, "loadComplete: ok!"); } }) .onRender(new OnRenderListener() { @Override public void onInitiallyRendered(int nbPages) { } }) .onPageChange(new OnPageChangeListener() { @Override public void onPageChanged(int page, int pageCount) { Log.d(TAG, "onPageChanged: 当前是第"+page+"页 总共"+pageCount); } }) .onPageScroll(new OnPageScrollListener() { @Override public void onPageScrolled(int page, float positionOffset) { } }) .load(); pdfView.fromFile(new File(filePath)) .enableSwipe(true) // 屏幕滑动 .enableDoubletap(false) //禁双击 .spacing(10) //页面之间距离 dp .enableAntialiasing(true) .pageFitPolicy(FitPolicy.WIDTH) //模式来适应视图中的页面 .pageSnap(true) //将页面对齐到屏幕边界 .nightMode(false) .load();
标签:pdfView,false,PDFViewer,电子书,page,阅读器,new,true,pages From: https://www.cnblogs.com/remix777/p/17904782.html