Search code examples
androidmupdf

Attach icon to link on MuPDF


I am using MuPDF library in my android project. I implemented it clearly and it's working fine. In my PDFs there is lots of link to navigate browser, but users can't figure out them. I want to add a icon over layouts where the items has got navigation link. How can I do that? Thanks for helping.


Solution

  • I found a way. In PageView.java class, there is a method called **setPage(int page, PointF size)** There is a block which is drawing content on highlight links.

    if (!mIsBlank && mLinks != null && mHighlightLinks) {
                        paint.setStrokeWidth(2);
                        for (LinkInfo link : mLinks) {
                            RectF rectfa = new RectF((link.rect.left - 2) * scale, (link.rect.top - 2) * scale, (link.rect.right + 2) * scale, (link.rect.bottom + 2) * scale);
                            paint.setStyle(Paint.Style.FILL);
                            paint.setColor(LINK_COLOR);
                            canvas.drawRoundRect(rectfa, 3 * scale, 3 * scale, paint);
    
                            paint.setStyle(Paint.Style.STROKE);
                            paint.setColor(HIGHLIGHT_COLOR);
                            canvas.drawRoundRect(rectfa, 3 * scale, 3 * scale, paint);
    
                            int left = (int) ((link.rect.left - 2) * scale);
                            int right = (int) ((link.rect.right + 2) * scale);
                            int top = (int) ((link.rect.top - 2) * scale);
                            int bottom = (int) ((link.rect.bottom + 2) * scale);
    
                            Rect dstRectForRender = new Rect(right - bitmap.getWidth(), top, right, top + bitmap.getHeight());
                            canvas.drawBitmap(bitmap, null, dstRectForRender, null);// I draw my bitmap on here.
                        }
                    }