Guides
内容编辑
内容编辑模式允许用户直接编辑 PDF 页面中的文字和图片。通过 ContentEditorConfig 可配置可编辑类型、工具按钮和默认文本属性。
可编辑类型
availableTypes 控制内容编辑工具栏中显示的编辑类型:
json
{
"contentEditorConfig": {
"availableTypes": [
"editorText",
"editorImage"
]
}
}| 值 | 说明 |
|---|---|
editorText | 编辑文本区域 |
editorImage | 编辑图片区域 |
可用工具
json
{
"contentEditorConfig": {
"availableTools": [
"setting",
"undo",
"redo"
]
}
}| 值 | 说明 |
|---|---|
setting | 属性设置按钮 |
undo | 撤销 |
redo | 重做 |
默认文本属性
通过 initAttribute 配置新建文本区域时的默认属性:
json
{
"contentEditorConfig": {
"initAttribute": {
"text": {
"fontColor": "#000000",
"fontColorAlpha": 255,
"fontSize": 30,
"isBold": false,
"isItalic": false,
"alignment": "left",
"familyName": "Helvetica",
"styleName": "Regular"
}
}
}
}| 字段 | 说明 |
|---|---|
fontColor | 文字颜色 |
fontColorAlpha | 文字不透明度(0-255) |
fontSize | 字号 |
isBold | 是否加粗 |
isItalic | 是否斜体 |
alignment | 对齐方式:"left"、"center"、"right" |
familyName | 字体名称 |
styleName | 字体样式 |
CEditToolbar 组件
CEditToolbar 是内容编辑工具栏的核心 UI 组件,位于 com.compdfkit.tools.contenteditor.pdfcontenteditorbar 包中。
相关类
| 类 | 说明 |
|---|---|
CEditToolbar | 内容编辑工具栏主视图 |
CContentEditorToolListAdapter | 编辑类型列表适配器 |
CContentEditorToolBean | 编辑工具项数据模型 |
属性编辑 Fragment
| 编辑类型 | Fragment 类 |
|---|---|
| 文本 | CEditTextPropertiesFragment |
| 图片 | CEditImagePropertiesFragment |
图片操作
内容编辑模式下选中图片后,上下文菜单支持以下操作:
- 旋转:左转/右转
- 替换:从相册选择图片替换
- 导出:将图片导出到设备
- 透明度:设置 25%/50%/75%/100%
- 水平/垂直翻转
- 裁剪:自由裁剪图片区域
- 复制/剪切/删除
这些操作通过 上下文菜单 的 contentEditorMode 配置控制。