【问题标题】:PDFTron for android - draw annotation bugPDFTron for android - 绘制注释错误
【发布时间】:2017-05-22 08:19:21
【问题描述】:

我正在尝试绘制注释,并且在 80% 的时间内注释绘制正确,但有时注释在中间被剪切,在我放大和缩小之后,注释完全绘制。

这是我绘制注释的代码:

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 个红色方块),第一个在中间被剪掉

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

【问题讨论】:

    标签: android annotations drawing pdftron


    【解决方案1】:

    我认为annotationData.getPage() 返回的内容与mAnnotPageNum 的内容之间存在差异。

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

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

    我会改变的其他事情。

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

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

    【讨论】:

    • 感谢 Ryan 的回答,你说得对,annotationData.getPage() 和 mAnnotPageNum 不一样,我修复了但问题没有解决。
    • 所以如果我想要不同大小的注释,你推荐使用不同的注释吗?
    • 如果您的目标是拥有具有自定义外观的注释,例如图像,那么 RubberStamp 注释将是最佳选择。或者你可以做一个方形注释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多