2

I am drawing ink annotation from points stored in db. Where those points were extracted from previously drawn shape over pdf. I have referred this example given by PDFTron but I am not able to see annotation drawn on page in proper manner. Actual Image Actual drawing

Drawn Programmatically Drawn programmatically Here is the code I have used for drawing annotation.

for (Integer integer : uniqueShapeIds) {
                        Config.debug("Shape Id's unique "+integer);
                        pdftron.PDF.Annots.Ink ink = pdftron.PDF.Annots.Ink.create(
                                mPDFViewCtrl.getDoc(),
                                getAnnotationRect(pointsArray, integer));
                        for (SaveAnnotationState annot : pointsArray) {
                            Config.debug("Draw "+annot.getxCord()+" "+annot.getyCord()+" "+annot.getPathIndex()+" "+annot.getPointIndex());
                            Point pt = new Point(annot.getxCord(), annot.getyCord());

                            ink.setPoint(annot.getPathIndex(), annot.getPointIndex(),pt);
                            ink.setColor(
                                    new ColorPt(annot.getR()/255, annot.getG()/255, annot
                                            .getB()/255), 3);
                            ink.setOpacity(annot.getOpacity());
                            BorderStyle border=ink.getBorderStyle();
                            border.setWidth(annot.getThickness());
                            ink.setBorderStyle(border);

                        }
                        ink.refreshAppearance();
                        Page page = mPDFViewCtrl.getDoc().getPage(mPDFViewCtrl.getCurrentPage());
                        Annot mAnnot=ink;
                        page.annotPushBack(mAnnot);
                        mPDFViewCtrl.update(mAnnot, mPDFViewCtrl.getCurrentPage());


                    }

can any one tell me what is going wrong here?

Manoj
  • 2,799
  • 5
  • 30
  • 49

1 Answers1

0

On a typical PDF page, the bottom left corner of the page is coordinate 0,0. However, for annotations the origin is the bottom left corner of the rectangle specified in the BBox entry. The BBox entry is the 3rd parameter of you call to Ink.Create, which is called pos unfortunately.

This means the Rect passed into Ink.Create, is supposed to be the minimum axis-aligned bounding box of the all the points that make up the Ink Annot.

I suspect in your call to getAnnotationRect you start with Rect(), which is really Rect(0,0,0,0), so when you union all the other points you end up with an inflated Rect.

What you should do is store the BBox in your database, by calling Annot.getRect().

If this is not possible, or too late, then initialize the Rect with the first point in your database.

Rect rect = new Rect(pt.x, pt.y, pt.x, pt.y);

API: http://www.pdftron.com/pdfnet/mobile/docs/Android/pdftron http://www.pdftron.com/pdfnet/mobile/docs/Android/pdftron/PDF/Annot.html#getRect%28%29/PDF/Annot.html#create%28pdftron.SDF.Doc,%20int,%20pdftron.PDF.Rect%29

Ryan
  • 2,473
  • 1
  • 11
  • 14