How to insert or delete points in an ink annotation?

105 views
Skip to first unread message

Shirley Gong

unread,
Jul 3, 2014, 4:53:09 PM7/3/14
to pdfne...@googlegroups.com
Q: Is it possible to insert a path into an existing ink annotation ? Or split a single path into multiple paths ?

A: Ink annotation consists of inkList object which is array of points array. The following snippet shows how to remove the last point from array with pathIndex from an ink annotation to a newly created array appended to the end of the inkList:

        // ink - ink annotation to be modified
        // pathIndex - ink annotation can contain more than one inkList, pathIndex specifies index of the inkList 
        void InkListSample(pdftron.PDF.Annots.Ink ink, int pathIndex)
        {
            Obj il = ink.GetSDFObj().FindObj("InkList");
            if (il != null && il.IsArray() && pathIndex < il.Size())
            {
                // create a new inkList 
                Obj th1 = il.InsertArray(il.Size());

                Obj th0 = il.GetAt(pathIndex);
                if (th0 != null && th0.IsArray())
                {
                    // index of last point
                    // each inkList contains: [x1,y1,x2,y2,x3,y3...]
                    int i = th0.Size() / 2 - 1;

                    // get the last point
                    double ptx = th0.GetAt(i * 2).GetNumber(); // x coordinate of the last point in the current inkList
                    double pty = th0.GetAt(i * 2 + 1).GetNumber(); // y coordinate of the last point in the current inkList
                    Point pt = new Point(ptx, pty);

                    // remove the last point from the current inkList
                    th0.EraseAt(i * 2 + 1);
                    th0.EraseAt(i * 2);

                    // add the point to the new inkList                    
                    th1.PushBackNumber(pt.x);
                    th1.PushBackNumber(pt.y);
                }
            }
        }
Reply all
Reply to author
Forward
0 new messages