Guides
上下文菜单
选中注释、文本、表单或内容编辑对象时,会弹出上下文菜单(Context Menu)以支持对象操作。ContextMenuConfig 可控制菜单的样式及各场景下的菜单项列表。
全局样式
json
{
"contextMenuConfig": {
"backgroundColor": "",
"fontSize": 14,
"padding": [0, 0, 0, 0],
"iconSize": 36
}
}1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
| 字段 | 说明 |
|---|---|
backgroundColor | 菜单背景颜色(空字符串使用默认) |
fontSize | 菜单文字大小 |
padding | 菜单内边距 [left, top, right, bottom] |
iconSize | 图标大小 |
全局菜单
global 配置适用于所有模式的全局上下文菜单:
json
{
"contextMenuConfig": {
"global": {
"screenshot": [
{ "key": "exit" },
{ "key": "share" }
]
}
}
}1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
阅读模式菜单
viewMode 配置阅读模式下的菜单:
json
{
"contextMenuConfig": {
"viewMode": {
"textSelect": [
{ "key": "copy" }
]
}
}
}1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
注释模式菜单
annotationMode 包含以下子菜单场景:
文本选中
json
"textSelect": [
{ "key": "copy" },
{ "key": "highlight" },
{ "key": "underline" },
{ "key": "strikeout" },
{ "key": "squiggly" }
]1
2
3
4
5
6
7
2
3
4
5
6
7
长按空白区域
json
"longPressContent": [
{ "key": "paste" },
{ "key": "note" },
{ "key": "textBox" },
{ "key": "stamp" },
{ "key": "image" }
]1
2
3
4
5
6
7
2
3
4
5
6
7
Markup 注释(高亮/下划线/删除线/波浪线)
json
"markupContent": [
{ "key": "properties" },
{ "key": "note" },
{ "key": "reply" },
{ "key": "viewReply" },
{ "key": "delete" }
]1
2
3
4
5
6
7
2
3
4
5
6
7
其他注释类型
| 场景 | 配置键 | 支持的菜单项 |
|---|---|---|
| 手写(Ink) | inkContent | properties、note、reply、viewReply、delete |
| 形状(Shape) | shapeContent | properties、note、reply、viewReply、delete |
| 文本框(FreeText) | freeTextContent | properties、edit、reply、viewReply、delete |
| 音频(Sound) | soundContent | reply、viewReply、play、record、delete |
| 图章(Stamp) | stampContent | note、reply、viewReply、delete、rotate |
| 签名图章 | signStampContent | signHere、delete、rotate |
| 链接(Link) | linkContent | edit、delete |
内容编辑模式菜单
contentEditorMode 包含以下场景:
文本区域
json
"editTextAreaContent": [
{ "key": "properties" },
{ "key": "edit" },
{ "key": "cut" },
{ "key": "copy" },
{ "key": "delete" }
]1
2
3
4
5
6
7
2
3
4
5
6
7
选中文本
json
"editSelectTextContent": [
{ "key": "properties" },
{ "key": "opacity", "subItems": ["25%", "50%", "75%", "100%"] },
{ "key": "cut" },
{ "key": "copy" },
{ "key": "delete" }
]1
2
3
4
5
6
7
2
3
4
5
6
7
文本输入
json
"editTextContent": [
{ "key": "select" },
{ "key": "selectAll" },
{ "key": "paste" }
]1
2
3
4
5
2
3
4
5
图片区域
json
"imageAreaContent": [
{ "key": "properties" },
{ "key": "rotateLeft" },
{ "key": "rotateRight" },
{ "key": "replace" },
{ "key": "export" },
{ "key": "opacity", "subItems": ["25%", "50%", "75%", "100%"] },
{ "key": "flipHorizontal" },
{ "key": "flipVertical" },
{ "key": "crop" },
{ "key": "delete" },
{ "key": "copy" },
{ "key": "cut" }
]1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
路径区域
json
"editPathContent": [
{ "key": "delete" }
]1
2
3
2
3
长按空白区域
json
"longPressWithEditTextMode": [
{ "key": "addText" },
{ "key": "paste" },
{ "key": "keepSourceFormatingPaste" }
]1
2
3
4
5
2
3
4
5
json
"longPressWithEditImageMode": [
{ "key": "addImages" },
{ "key": "paste" }
]1
2
3
4
2
3
4
搜索替换
json
"searchReplace": [
{ "key": "replace" }
]1
2
3
2
3
表单模式菜单
formMode 为各表单类型配置菜单:
json
{
"contextMenuConfig": {
"formMode": {
"textField": [{ "key": "properties" }, { "key": "delete" }],
"checkBox": [{ "key": "properties" }, { "key": "delete" }],
"radioButton": [{ "key": "properties" }, { "key": "delete" }],
"listBox": [{ "key": "options" }, { "key": "properties" }, { "key": "delete" }],
"comboBox": [{ "key": "options" }, { "key": "properties" }, { "key": "delete" }],
"signatureField": [{ "key": "startToSign" }, { "key": "delete" }],
"pushButton": [{ "key": "options" }, { "key": "properties" }, { "key": "delete" }]
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
添加自定义菜单项
在任意菜单场景中添加自定义按钮:
1. 配置 JSON
json
{
"contextMenuConfig": {
"annotationMode": {
"markupContent": [
{ "key": "properties" },
{ "key": "note" },
{
"key": "custom",
"identifier": "custom_markup_action_get_text",
"title": "Get Text",
"icon": "ic_test_get_text",
"showType": "text"
},
{ "key": "delete" }
]
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| 字段 | 说明 |
|---|---|
key | 自定义按钮必须为 "custom" |
identifier | 唯一标识符,在回调中区分不同按钮 |
title | 显示文本 |
icon | 图标资源名(需放在 res/drawable) |
showType | 显示方式:"text" 或 "icon" |
2. 添加回调
java
CPDFCustomEventCallbackHelper.getInstance().addCustomEventCallback(extraMap -> {
String customEventType = extraMap.get(
CPDFCustomEventField.CUSTOM_EVENT_TYPE).toString();
if (CPDFCustomEventType.CONTEXT_MENU_ITEM_TAPPED.equals(customEventType)) {
String identifier = extraMap.get(CPDFCustomEventField.IDENTIFIER).toString();
switch (identifier) {
case "custom_markup_action_get_text":
CPDFAnnotation annotation = (CPDFAnnotation) extraMap.get(
CPDFCustomEventField.ANNOTATION);
if (annotation instanceof CPDFMarkupAnnotation) {
String text = ((CPDFMarkupAnnotation) annotation).getMarkedText();
CToastUtil.showToast(getApplicationContext(), text);
}
break;
}
}
});1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
kotlin
CPDFCustomEventCallbackHelper.getInstance().addCustomEventCallback { extraMap ->
val customEventType = extraMap[CPDFCustomEventField.CUSTOM_EVENT_TYPE].toString()
if (CPDFCustomEventType.CONTEXT_MENU_ITEM_TAPPED == customEventType) {
val identifier = extraMap[CPDFCustomEventField.IDENTIFIER].toString()
when (identifier) {
"custom_markup_action_get_text" -> {
val annotation = extraMap[CPDFCustomEventField.ANNOTATION]
if (annotation is CPDFMarkupAnnotation) {
CToastUtil.showToast(applicationContext, annotation.markedText)
}
}
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
效果示意
