目前我正在开发需要在 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();