Insert an annotation at a position where the screen was touched

Hello, I am trying to insert Ink annotation on my pdf document, my objective is to insert an annotation relative to the point that has been touched by the user. Currently the code adds the annotion at the bottom left corner of the page. Secondly How can I get the current page number?

    private void insertXsymbol(MotionEvent event) {
        Page first_page = null;
        try {
            first_page = doc.getPage(1);
            com.pdftron.pdf.annots.Ink ink = com.pdftron.pdf.annots.Ink.create(doc, new Rect(500, 100, 5, 500));
            //Point pt3 = new Point(110, 10);
            Point pt3 = new Point(event.getX(), event.getY());
            //pt3.x = 110; pt3.y = 10;
            //ink.setPoint(0, 0, pt3);
            pt3.x = 20;
            pt3.y = 60;
            ink.setPoint(0, 1, pt3);

            pt3.x = 30;
            pt3.y = 50;
            ink.setPoint(0, 2, pt3);

            pt3.x = 40;
            pt3.y = 40;
            ink.setPoint(0, 3, pt3);

            pt3.x = 50;
            pt3.y = 30;
            ink.setPoint(0, 4, pt3);

            pt3.x = 60;
            pt3.y = 20;
            ink.setPoint(0, 4, pt3);
            /*-----------------------------------*/
            // ink.setPoint(1, 0, pt3);
            pt3.x = 20;
            pt3.y = 20;
            ink.setPoint(1, 1, pt3);

            pt3.x = 30;
            pt3.y = 30;
            ink.setPoint(1, 2, pt3);

            pt3.x = 40;
            pt3.y = 40;
            ink.setPoint(1, 3, pt3);

            pt3.x = 50;
            pt3.y = 50;
            ink.setPoint(1, 4, pt3);

            pt3.x = 60;
            pt3.y = 60;
            ink.setPoint(1, 4, pt3);
            /*-----------------------------------*/
          /*   pt3.x = 200; pt3.y = 100;
            ink.setPoint(1, 2, pt3);
            pt3.x = 166; pt3.y = 86;
            ink.setPoint(2, 0, pt3);
            pt3.x = 196; pt3.y = 96;
            ink.setPoint(2, 1, pt3);
            pt3.x = 221; pt3.y = 121;
            ink.setPoint(2, 2, pt3);
            pt3.x = 288; pt3.y = 188;
            ink.setPoint(2, 3, pt3);*/
            ink.setColor(new ColorPt(0, 1, 1), 3);
            first_page.annotPushBack(ink);

ink.refreshAppearance();
        } catch (PDFNetException e) {
            e.printStackTrace();
        }
    }

Could you clarify why you are not using the Tools code that does this for you? In particular the FreeHandCreate.java file?

At the very least that code shows how to do it your self.

The main issue with your code is that the quad points are within an inch of the bottom left corner of the page (assuming the page is “normal”). The quad points are not relative to the rect of the quad, or each other, but simply from the “origin”.

Also, you are not translating the touch event coordinates, which are in screen space, but annotations are in PDF page space. This is all handled already in the provided tools code.