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

TOPIC:

Create custom Annotation from coordinates 5 years 5 months ago #14213

  • Faris
  • Faris's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
Hi support team,

I've asked around the iOS forum for something similar : -
www.radaeepdf.com/forum/ios-dev/4169-cre...ion-from-coordinates

Now, I am looking for it for Android version.

I would like to create custom rectangular annotations, based on coordinates received (x, y, height, width) , programmatically on the PDF files when the viewer started.
Would also want the annotations to be clickable to do some actions (open a new view controller / alertDialog etc.)

For example,
I would like to annotate the text like in attachment picture, and the user will be only able to click on them but can't do any editing.

Would like ask the support team whether this possible with radaeepdf kit?

Thanks in advance,
Faris
Attachments:

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

Create custom Annotation from coordinates 5 years 5 months ago #14216

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
Dear Faris,

here is a sample code also for Android version, you can use it in PDFLayoutView class:
            int x = 100;
            int y = 100;
            int width = 400;
            int height = 100;

            float rect[] = new float[4];
            rect[0] = x;
            rect[1] = y;
            rect[2] = rect[0] + width;
            rect[3] = rect[1] + height;
            PDFPos pos = m_layout.vGetPos(0, 0);//where rect is in screen coordinate.
            VPage vpage = m_layout.vGetPage(pos.pageno);
            Matrix mat = vpage.CreateInvertMatrix(m_layout.vGetX(), m_layout.vGetY());
            mat.TransformRect(rect);
            Page page = m_doc.GetPage(0);
            page.AddAnnotRect(rect, vpage.ToPDFSize(Global.rect_annot_width), Global.rect_annot_color, Global.rect_annot_fill_color);
            mat.Destroy();
            PDFUpdateCurrPage();

About action on annot click you can use the same logic of iOS version, using OnAnnotClicked method, implemented in PDFReaderAct class
The following user(s) said Thank You: Faris

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

Create custom Annotation from coordinates 5 years 4 months ago #14225

  • afarhan39
  • afarhan39's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
Hi Emanuele,

I managed to use RadaeePDF to display PDF.
RadaeePDFManager radaeePDFManager = new RadaeePDFManager();
File file = new File(context.getFilesDir(), Utils.modFileName(epaperItem.getName()));
radaeePDFManager.openFromPath(context, file.getAbsolutePath(), "");

Similar to Faris, I also want to draw custom rectangular annotations based on coordinates received (x, y, height, width).
I have looked into your answer, but I confused on how to implement it.
On each page have different rectangular annotations, and I have like around 40+ pages to annotate.
How do I call this function?
Would love to receive some helps.

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

Create custom Annotation from coordinates 5 years 4 months ago #14227

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
Hi,

you can add a new method in PDFLayoutView class with the code of my previous post.
In my example I used static x, y, width, height and the current page to add the annotation, but you can edit the code and use variables to add the annotation on your page taking x, y, width, height and page as input parameters, than add a for cycle to call the function for each needed page.

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

Create custom Annotation from coordinates 5 years 4 months ago #14228

  • afarhan39
  • afarhan39's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 2
  • Thank you received: 0
Hi Emanuele,
Thanks for the fast response.

For now I'm using AboutActivity in demo Android that RadaeePDF provided, since it the only one I see have PDFLayoutView in use.
I tried based on your suggestion, which to add new function A to draw rect.
I tried and error on which method shall I call this function A, since I don't really know where shall I call this.
void OnPDFPageModified(int pageno);
void OnPDFPageChanged(int pageno);
void OnPDFPageDisplayed(Canvas canvas, IVPage vpage);
void OnPDFPageRendered(IVPage vpage);
But none of them show the rectangle.
Further checking the method, I found out the method page.AddAnnotRect(..) return false. What does it means?

TLDR
1. Where shall I call your code mention?
2. Why does page.AddAnnotRect(...) return false?

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

Create custom Annotation from coordinates 5 years 4 months ago #14232

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
First of all, I suggest to use PDFViewController class (contained in PDFViewAct), as it implements all methods and callbacks.
Now you can choose the event where you will call your new method, for example you can check it with OnBlankTapped method, triggered where you tap on the pdf.
AboutActivity is used only to show the "about" info, for that reason it doesn't contain the toolbar.

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

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