Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF

TOPIC:

how to move the added text at pdf 8 years 2 months ago #10236

  • ankur123987
  • ankur123987's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Available as freelancer (ex website to app 30min)
  • Posts: 97
  • Thank you received: 0
HI Radaeepdf team,

I am able to add the text at pdf file but is there any mechanism to move my added text at any place of pdf ?

Please help

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

how to move the added text at pdf 8 years 2 months ago #10240

  • max.pfeiffer
  • max.pfeiffer's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 14
  • Thank you received: 1
+1, same problem here.

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

how to move the added text at pdf 8 years 2 months ago #10241

  • ankur123987
  • ankur123987's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Available as freelancer (ex website to app 30min)
  • Posts: 97
  • Thank you received: 0
Hi Radaeepdf team,

is that feasible? i could not find any supported method regarding this .

Please help

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

how to move the added text at pdf 8 years 2 months ago #10242

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
to enable edit text moving you have to edit OnPDFSingleTapped method of PDFReader class as following:
public boolean OnPDFSingleTapped(float x, float y)
	{
		if( m_status == STA_NORMAL || m_status == STA_ANNOT )
		{
			m_annot_pos = m_view.vGetPos((int)x, (int)y);
			m_annot_page = m_view.vGetPage(m_annot_pos.pageno);
			final Page page = m_annot_page.GetPage();
			if( page == null ) m_annot = null;
			else m_annot = page.GetAnnotFromPoint(m_annot_pos.x, m_annot_pos.y);
			if( m_annot == null )
			{
				m_annot_page = null;
				m_annot_pos = null;
				m_annot_rect = null;
				m_view.vSetLock(0);
				if( m_listener != null && m_status == STA_ANNOT )
					m_listener.OnAnnotClicked(m_annot_page, null);
				m_status = STA_NORMAL;
			}
			else
			{
				m_annot_rect = m_annot.GetRect();
				int px = m_annot_page.GetVX(m_view.vGetX());
				int py = m_annot_page.GetVY(m_view.vGetY());
				float tmp = m_annot_rect[1];
				m_annot_rect[0] = m_annot_page.ToDIBX(m_annot_rect[0]) + px;
				m_annot_rect[1] = m_annot_page.ToDIBY(m_annot_rect[3]) + py;
				m_annot_rect[2] = m_annot_page.ToDIBX(m_annot_rect[2]) + px;
				m_annot_rect[3] = m_annot_page.ToDIBY(tmp) + py;
				m_view.vSetLock(3);
				m_status = STA_ANNOT;
				if( m_doc.CanSave() && m_annot.GetEditType() > 3 )	//don't open edit text requetser
				{
					int[] location = new int[2];  
					getLocationOnScreen(location);
                    m_pEdit = new PopupWindow(LayoutInflater.from(getContext()).inflate(R.layout.pop_edit, null) );
                    m_pEdit.setFocusable(true);
                    m_pEdit.setTouchable(true);
                    BitmapDrawable bitmap = new BitmapDrawable();//add back
                    m_pEdit.setBackgroundDrawable(bitmap);
					m_pEdit.setWidth((int)(m_annot_rect[2] - m_annot_rect[0]));
					m_pEdit.setHeight((int)(m_annot_rect[3] - m_annot_rect[1]));
					final EditText edit = (EditText)m_pEdit.getContentView().findViewById(R.id.annot_text);
					edit.setBackgroundColor(0xFFFFFFC0);
                    m_pEdit.setOnDismissListener(new PopupWindow.OnDismissListener() {
                        @Override
                        public void onDismiss() {
                            if (m_edit_type == 1)//edit box
                            {
                                m_annot.SetEditText(edit.getText().toString());
                                m_view.vRenderSync(m_annot_page);
                                if (m_listener != null)
                                    m_listener.OnPageModified(m_annot_page.GetPageNo());
                                PDFEndAnnot();
                            }
                            m_edit_type = 0;
                        }
                    });
					float fsize = m_annot.GetEditTextSize() * m_annot_page.GetScale();
					edit.setTextSize(TypedValue.COMPLEX_UNIT_PX, fsize);
					edit.setPadding(2, 2, 2, 2);
					switch( m_annot.GetEditType() )
					{
					case 1:
						edit.setSingleLine();
						edit.setInputType(InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_VARIATION_NORMAL);
						break;
					case 2:
						edit.setSingleLine();
						edit.setInputType(InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_VARIATION_PASSWORD);
						break;
					case 3:
						edit.setSingleLine(false);
						edit.setInputType(InputType.TYPE_CLASS_TEXT + InputType.TYPE_TEXT_VARIATION_NORMAL);
						break;
					}
					int maxlen = m_annot.GetEditMaxlen();
					if( maxlen > 0 )
						edit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxlen)});
					else
						edit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1020)});
					edit.setText(m_annot.GetEditText());
					m_edit_type = 1;
					m_pEdit.showAtLocation(this, Gravity.NO_GRAVITY, (int)m_annot_rect[0] + location[0], (int)m_annot_rect[1] + location[1]);
				}
				if( m_doc.CanSave() && m_annot.GetComboItemCount() >= 3 )	//move  edit text
				{
					int[] location = new int[2];  
					getLocationOnScreen(location);
					String opts[] = new String[m_annot.GetComboItemCount()];
					int cur = 0;
					while( cur < opts.length )
					{
						opts[cur] = m_annot.GetComboItem(cur);
						cur++;
					}
                    m_pCombo = new PopupWindow(LayoutInflater.from(getContext()).inflate(R.layout.pop_combo, null));
                    m_pCombo.setFocusable(true);
                    m_pCombo.setTouchable(true);
                    BitmapDrawable bitmap = new BitmapDrawable();//add back
                    m_pCombo.setBackgroundDrawable(bitmap);
					m_pCombo.setWidth((int)(m_annot_rect[2] - m_annot_rect[0]));
					if( (m_annot_rect[3] - m_annot_rect[1] - 4) * opts.length > 250 )
						m_pCombo.setHeight(250);
					else
						m_pCombo.setHeight((int)(m_annot_rect[3] - m_annot_rect[1] - 4) * opts.length);
					ComboList combo = (ComboList)m_pCombo.getContentView().findViewById(R.id.annot_combo);
					combo.set_opts(opts);
					combo.setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                            m_sel_index = i;
                            m_pCombo.dismiss();
                        }
                    });
                    m_pCombo.setOnDismissListener(new PopupWindow.OnDismissListener() {
                        @Override
                        public void onDismiss() {
                            if (m_edit_type == 2)//combo
                            {
                                if (m_sel_index >= 0) {
                                    m_annot.SetComboItem(m_sel_index);
                                    m_view.vRenderSync(m_annot_page);
                                    if (m_listener != null)
										m_listener.OnPageModified(m_annot_page.GetPageNo());
                                }
                                m_sel_index = -1;
                                PDFEndAnnot();
                            }
                            m_edit_type = 0;
                        }
                    });
					m_edit_type = 2;
					m_sel_index = -1;
					m_pCombo.showAtLocation(this, Gravity.NO_GRAVITY, (int)m_annot_rect[0] + location[0], (int)(m_annot_rect[3] + location[1]));
				}
				if( m_listener != null )
					m_listener.OnAnnotClicked(m_annot_page, m_annot);
				invalidate();
			}
			return true;
		}
		return false;
	}

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

how to move the added text at pdf 8 years 2 months ago #10248

  • ankur123987
  • ankur123987's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Available as freelancer (ex website to app 30min)
  • Posts: 97
  • Thank you received: 0
Hi Davide,

Could you make this method is compatible with PDFLayoutView, if i use the PDFreader class then my other layouts does not work . I tried to add the text by using PDFReader as its lack of many methods for example (m_view.vGetPage ,m_view.vGetX(), m_view.vGetY() .. etc )

No redo and undo methods in PDFreader so cant use this class . I wanted maximum functionality that is available in only PDFLayoutView class . or in PDFLayoutListener class .

Please provide the methods for these class . I tried to above method with public boolean onSingleTapUp(MotionEvent e) function of PDFLayoutListener but nothing work

please help

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

how to move the added text at pdf 8 years 2 months ago #10273

  • max.pfeiffer
  • max.pfeiffer's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 14
  • Thank you received: 1
Hi Ankuri,
I just managed to do that using the PDFLayoutView class. You need to change the method "public boolean onSingleTapUp(MotionEvent e)" of the PDFGestureListener to make that work.

When single tapping a text annotion this method is displaying an edit text by standard. I changed that so it has the same behaviour when tapping on a stamp: you can move the text annotation around like the stamp.

In the attachment you find my class with the changes. I also modified other functions in that class to suit my needs. So be careful when using it.

Greetings,
Max

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

Last edit: by max.pfeiffer.
Powered by Kunena Forum