用于android的PDFTron-绘制注释错误 我试图画注释,在80%的时间里注释正确地画出来,但是有时注释在中间被剪裁,在放大之后,注释缩小了。

用于android的PDFTron-绘制注释错误 我试图画注释,在80%的时间里注释正确地画出来,但是有时注释在中间被剪裁,在放大之后,注释缩小了。,android,annotations,drawing,pdftron,Android,Annotations,Drawing,Pdftron,这是我绘制注释的代码: public void createNoteIconOnPage(AnnotationData annotationData, Point noteIconPoint) { try { mPDFView.docLock(true); PDFDoc pdfDoc = mPDFView.getDoc(); double[] pts = mPDFView.convScreenPtToPagePt(noteIconPoint

这是我绘制注释的代码:

public void createNoteIconOnPage(AnnotationData annotationData, Point noteIconPoint) {
    try {
        mPDFView.docLock(true);
        PDFDoc pdfDoc = mPDFView.getDoc();
        double[] pts = mPDFView.convScreenPtToPagePt(noteIconPoint.x, noteIconPoint.y, annotationData.getPage());
        Point p = new Point(pts[0], pts[1]);
        com.pdftron.pdf.annots.Text text = com.pdftron.pdf.annots.Text.create(pdfDoc, p);
        text.setUniqueID(annotationData.getUniqueId());
        //creating the annotation appearance - icon

        // Let's create an appearance for the annotation using an image
        ElementBuilder builder = new ElementBuilder();
        ElementWriter writer = new ElementWriter();
        writer.begin(pdfDoc);

        Bitmap imageBitmap = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888);
        imageBitmap.eraseColor(Color.RED);
        Image image = Image.create(mPDFView.getDoc(), imageBitmap);

    //    Image image = Image.create(pdfDoc, annotationData.getDrawable());

        int w = image.getImageWidth(), h = image.getImageHeight();

        Element element = builder.createImage(image, 0, 0, w, h);

        writer.writePlacedElement(element);

        writer.writeElement(builder.createTextBegin(Font.create(pdfDoc, Font.e_times_roman), 12));
        writer.writeElement(element);
        writer.writeElement(builder.createTextEnd());

        Obj appearance = writer.end();
        appearance.putRect("BBox", 0.1, 0.1, w, h);
        text.setAppearance(appearance);

        /*
        The left icons spouse to be bigger the the regular icons
         */
        if(annotationData.getType() == AnnotationData.AnnotationType.LINK && (annotationData.getShard() == AnnotationData.LEFT_LINK_A || annotationData.getShard() == AnnotationData.LEFT_LINK_B)){
            text.setRect(new Rect(pts[0],pts[1],pts[0] + 30,pts[1] + 30));
        }

        if (annotationData.getType() == AnnotationData.AnnotationType.NOTE) {
            text.setContents(AnnotationData.NOTE_TYPE_CONTENTS);
        } else if (annotationData.getType() == AnnotationData.AnnotationType.LINK) {
            text.setContents(AnnotationData.LINK_TYPE_CONTENTS);
        }

        Page page = pdfDoc.getPage(annotationData.getPage());
        if (page != null) {
            page.annotPushBack(text);
        }


        mAnnotPushedBack = true;
        mAnnot = text;
        mAnnotPageNum = mDownPageNum;
        buildAnnotBBox();

        mPDFView.update(mAnnot, mAnnotPageNum);
        raiseAnnotationAddedEvent(mAnnot, mAnnotPageNum);

    } catch (Exception ex) {
        Log.e(PDFTronReader.TAG, ex.toString());
        mNextToolMode = ToolManager.e_pan;

    } finally {
        mPDFView.docUnlock();
    }
    mPDFView.waitForRendering();
}
这就是它的外观:

如您所见,我们有3个左边大小的注释(3个红色正方形),第一个注释在中间剪切

有人知道为什么会这样吗?
谢谢大家。

我认为
annotationData.getPage()
返回的内容与
mAnnotPageNum
返回的内容不一致

我将围绕这两个变量之一合并这段代码。也就是说,使用其中之一。我怀疑20%的时间他们不是同一个数字

此外,文本注释只有一个位置,因为它们的大小是固定的。它们的缩放比例与普通注释不同。因此,我将注释掉对
buildAnnotBBox
的调用

其他事情我会改变

  • 如上所述,大小是固定的。因此,请删除以下行
    text.setRect(新的Rect(pts[0],pts[1],pts[0]+30,pts[1]+30))

  • 您将
    BBox
    原点设置为
    0.1
    ,根据您的自定义外观,该原点应为0


  • 谢谢Ryan的回答,你说得对annotationData.getPage()和mAnnotPageNum不一样,我已经解决了,但问题没有解决。因此,如果我想要不同大小的批注,你推荐哪种批注?如果你的目标是拥有自定义外观的批注,例如图像,那么RubberStamp注释将是最佳选择。或者你可以做一个正方形的注释。