Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about Android development and PDF

create URI link annotation over selected text

More
IP: 192.168.0.71 8 years 6 months ago #12581 by alaa88
hello, i'm trying to Create URI Annotation over selected text of PDF
@Override
public void OnPDFSelectEnd(final String text){
m_doc.GetPage(getCurrentPage()).AddAnnotURI(rects,text);
}
my problem here is how to get the rects of the selected text please advice?

thanks
More
IP: 192.168.0.71 8 years 6 months ago - 8 years 6 months ago #12584 by nermeen
To get the rect of the selected text, you need to go one step back (i.e. where OnPDFSelectEnd is called).
You can call the below method in PDFLayoutView.onTouchSelect as follows:
Code:
case MotionEvent.ACTION_CANCEL: if(m_sel != null) { m_sel.SetSel( m_annot_pos.x, m_annot_pos.y, m_annot_page.ToPDFX(event.getX(), m_layout.vGetX()), m_annot_page.ToPDFY(event.getY(), m_layout.vGetY()) ); invalidate(); float[] rect = getSelectionRect(event.getX(), event.getY()); if(m_listener != null) m_listener.OnPDFSelectEnd(m_sel.GetSelString()); } break;
getSelectionRect:
Code:
private float[] getSelectionRect(float lastX, float lastY) { float pt[] = new float[2]; pt[0] = m_annot_pos.x; pt[1] = m_annot_pos.y; Page page = m_doc.GetPage(m_annot_pos.pageno); page.ObjsStart(); int index1 = page.ObjsGetCharIndex(pt); pt[0] = m_annot_page.ToPDFX(lastX, m_layout.vGetX()); pt[1] = m_annot_page.ToPDFY(lastY, m_layout.vGetY()); int index2 = page.ObjsGetCharIndex(pt); if( index1 > index2 ) { int tmp = index1; index1 = index2; index2 = tmp; } index1 = page.ObjsAlignWord(index1, -1); index2 = page.ObjsAlignWord(index2, 1); float[] rect = new float[4]; float[] selectRect = new float[4]; page.ObjsGetCharRect(index1, rect); selectRect[0] = rect[0]; selectRect[1] = rect[1]; selectRect[2] = rect[2]; selectRect[3] = rect[3]; int tmp = index1 + 1; while( tmp <= index2 ) { page.ObjsGetCharRect(tmp, rect); float gap = (rect[3] - rect[1])/2; if( selectRect[1] == rect[1] && selectRect[3] == rect[3] && selectRect[2] + gap > rect[0] && selectRect[0] - gap < rect[2] ) { if( selectRect[0] > rect[0] ) selectRect[0] = rect[0]; if( selectRect[2] < rect[2] ) selectRect[2] = rect[2]; } else { if( selectRect[0] > rect[0] ) selectRect[0] = rect[0]; selectRect[1] = rect[1]; if( selectRect[2] < rect[2] ) selectRect[2] = rect[2]; if( selectRect[3] < rect[3] ) selectRect[3] = rect[3]; } tmp++; } return selectRect; }
Last edit: 8 years 6 months ago by nermeen.
Time to create page: 0.410 seconds
Powered by Kunena Forum