create URI link annotation over selected text - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Android development and PDF
  • Page:
  • 1

TOPIC: create URI link annotation over selected text

create URI link annotation over selected text 1 year 4 months ago #12581

  • alaa88
  • alaa88's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 1
  • Thank you received: 0
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

Please Log in or Create an account to join the conversation.

create URI link annotation over selected text 1 year 4 months ago #12584

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
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:
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:
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;
}

Please Log in or Create an account to join the conversation.

Last edit: by nermeen.
  • Page:
  • 1
Powered by Kunena Forum