Frequently Asked Question

Auto resize free text annotation height
最后更新 11 个月前

You can follow the article also on Android.

The default behavior of the free-text annotation (Type = 3) is that it has a fixed height regardless of its content.

If you need to resize the annotation height based on the content, you need to add the following code in onDismiss of m_pEdit.setOnDismissListener found in GLView.

Note: This is supported from version 3.53.5 (code is already included but commented in the demo project)

m_pEdit.setOnDismissListener(new PopupWindow.OnDismissListener() {
    @Override
    public void onDismiss() {
        if (m_annot != null) {
            // auto resize free-text annotation
            if(m_annot.GetType() == 3) {
                float old_pdf_rect[] = m_annot.GetRect();
                float new_height = m_pEdit.getContentHeight() / m_annot_page.GetScale();
                float new_pdf_rect[] = new float[4];
                new_pdf_rect[0] = old_pdf_rect[0];
                new_pdf_rect[2] = old_pdf_rect[2];
                new_pdf_rect[3] = old_pdf_rect[3];
                new_pdf_rect[1] = new_pdf_rect[3] - new_height;
                m_annot.SetRect(new_pdf_rect[0], new_pdf_rect[1], new_pdf_rect[2], new_pdf_rect[3]);
            }

            ...
        }
    }
});


正在加载……