barteksc AndroidPdfViewer库中的注释功能

时间:2018-10-05 10:03:08

标签: android pdfium

目前,我正在开发需要在PDF查看器中添加搜索功能的应用程序。

要加载pdf,我正在使用barteksc库。 https://github.com/barteksc/AndroidPdfViewer

我想知道以下内容:-

1)在现有库中, enableAnnotationRendering 方法的用途是什么。

2)如何在存在库中添加搜索和注释功能。

这是我当前正在使用的代码

 pdfView.fromFile(uri)
                .defaultPage(0)                   
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)                 
                .scrollHandle(new DefaultScrollHandle(this))
                .onPageError(this)
                .spacing(10)
                .onDraw(new OnDrawListener() {
                    @Override
                    public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {

                        // set a margin, otherwise depending on device resolution, border is not displayed (falls outside the component)
                        final float MARGIN = 1f;
                        // compute coordinates
                        float xLeft = (-1f * displayedPage * pageWidth) + MARGIN;
                        float xRight = (-1f * displayedPage * pageWidth) + pageWidth - MARGIN;
                        float yGlobalTop = MARGIN;
                        float yGlobalBottom = ((float) pdfView.getPageCount() * pageHeight) - MARGIN;
                        float yTop = (displayedPage * pageHeight) + MARGIN;
                        float yBottom = ((displayedPage + 1f) * pageHeight) - MARGIN;
                        // left vertical border
                        canvas.drawLine(xLeft,  yGlobalTop, xLeft,  yGlobalBottom, drawPaint);
                        // right vertical border
                        canvas.drawLine(xRight,  yGlobalTop, xRight,  yGlobalBottom, drawPaint);
                        // top origin horizontal border
                        canvas.drawLine(xLeft,  yGlobalTop, xRight,  yGlobalTop, drawPaint);
                        // bottom horizontal border up to current page - 2
                        for (int loopPage = 0; loopPage < (displayedPage - 1) && loopPage < pdfView.getPageCount(); loopPage++) {
                            float yLoopEnd = ((loopPage + 1f) * pageHeight) - MARGIN;
                            canvas.drawLine(xLeft,  yLoopEnd, xRight,  yLoopEnd, drawPaint);
                        }
                        // top and bottom horizontal borders for current page
                        // not in the loop to have correct borders when display page fills the screen
                        canvas.drawLine(xLeft,  yTop, xRight,  yTop, drawPaint);
                        canvas.drawLine(xLeft,  yBottom, xRight,  yBottom, drawPaint);
                        // bottom horizontal border up to last page
                        for (int loopPage = displayedPage + 1; loopPage < pdfView.getPageCount(); loopPage++) {
                            float yLoopEnd = ((loopPage + 1f) * pageHeight) - MARGIN;
                            canvas.drawLine(xLeft,  yLoopEnd, xRight,  yLoopEnd, drawPaint);
                        }
                    }
                })
                .onDrawAll(new OnDrawListener() {
                    @Override
                    public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {
                        Log.e("onDrawAll",pageWidth+":"+pageHeight+":"+displayedPage);
                    }
                })
                .pageFitPolicy(FitPolicy.WIDTH)
                .load();

0 个答案:

没有答案