Convert PDF coordinates to view layout coord - 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

TOPIC: Convert PDF coordinates to view layout coord

Convert PDF coordinates to view layout coord 1 year 2 months ago #12883

  • geertvm
  • geertvm's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0
Hi,

I have a custom layout (RelativeLayout) which holds a PDFLayoutView
and a custom toolbar (also a RelativeLayout with some imagebuttons)

First of all I want to detect if the user tapped on a visible signature field.
I think we can handle that by implementing the setOnTouchListener and converting the raw x and
y coordinates with the PDFLayout.PDFPos pdfPos = m_view.PDFGetPos(x, y);

I also want to draw some kind of overlay on visible signature fields (with known PDF coordinates).
I've started by implementing the PDFLayoutView.PDFLayoutListener() and the OnPageDisplayed
So I suppose it could be possible to draw a rectangle on the canvas...
How can I convert these PDF coordinates to the layout coordinates so that I can draw an rectangle on top of a visible signature field
(It's possible that this field is only visible after some scrolling...)

Thanks
Geert

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

Convert PDF coordinates to view layout coord 1 year 2 months ago #12887

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
You can implement PDFLayoutListener.OnPDFAnnotTapped (which get fired when an annot is tapped) and filter based on Annot type and annot filed type to detect a signature field.
You can also get the annotation rectangle (position) in PDF coordinates and convert it to view coordinates to be used later in OnPageDisplayed, check the below code:
@Override
	public void OnPDFAnnotTapped(VPage vpage, Annotation annot)
	{
		...
		if(annot != null && annot.GetType() == 20 && annot.GetFieldType() == 4) {
			float[] annotRect = annot.GetRect();
			float tmp = annotRect[1];
			annotRect[0] = vpage.GetVX(annotRect[0]) - m_view.PDFGetX();
			annotRect[1] = vpage.GetVY(annotRect[3]) - m_view.PDFGetY();
			annotRect[2] = vpage.GetVX(annotRect[2]) - m_view.PDFGetX();
			annotRect[3] = vpage.GetVY(tmp) - m_view.PDFGetY();
		}
		...
	}
Note: m_view.PDFGetX() and m_view.PDFGetY() are introduced in the latest version 3.14.2, you can add them in PDFLayoutView:
public float PDFGetX() {
		return m_layout != null ? m_layout.vGetX() : 0;
	}

	public float PDFGetY() {
		return m_layout != null ? m_layout.vGetY() : 0;
	}

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

Last edit: by nermeen.

Convert PDF coordinates to view layout coord 1 year 2 months ago #12888

  • geertvm
  • geertvm's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0
The digital signature field isn't recognized...
but the code helped me in displaying the overlay...
Attachments:

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

Convert PDF coordinates to view layout coord 1 year 2 months ago #12891

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
The pdf you have sent does not contain a signature field (it only contains a text).
As a consequence the code above wont work.
Same behavior with Acrobat and other readers.

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

Convert PDF coordinates to view layout coord 1 year 2 months ago #12893

  • geertvm
  • geertvm's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0
sorry, uploaded the wrong pdf... :(
This one has 2 visible signature fields...
Attachments:

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

Convert PDF coordinates to view layout coord 1 year 2 months ago #12894

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
We have tested your new pdf with the above code, and the annotations can be recognized.
Can you retest by adding the above code into the demo project?

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

Powered by Kunena Forum