Guides
内容编辑
ComPDF React Native SDK 支持多种内容编辑事件监听,以下是常用的内容编辑事件:
| 事件名称 | 描述 |
|---|---|
| onContentEditorStyleDialogDismissed | 当内容编辑属性弹窗关闭时触发,返回包含内容编辑类型的事件对象。 |
| CPDFEvent.EDITOR_SELECTION_SELECTED | 当用户选中内容编辑元素时触发,返回选中的内容编辑元素数据。 |
| CPDFEvent.EDITOR_SELECTION_DESELECTED | 当用户取消选中内容编辑元素时触发,返回取消选中的内容编辑元素数据。 |
要监听这些事件,可以在创建 CPDFReaderView 时传入关闭回调,或在创建后通过 addEventListener() 监听选中事件。例如:
tsx
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={configuration}
onContentEditorStyleDialogDismissed={(event) => {
console.log('Content editor style dialog dismissed:', event.type);
}}
/>onContentEditorStyleDialogDismissed 返回的事件对象结构如下:
tsx
{
type: 'editorText' | 'editorImage';
}其他内容编辑事件可以在创建 CPDFReaderView 后调用函数。例如:
tsx
pdfReaderRef.current?.addEventListener(
CPDFEvent.EDITOR_SELECTION_SELECTED,
(editArea) => {
// editArea 为 CPDFEditArea 对象
// text : CPDFEditTextArea 对象
// image : CPDFEditImageArea 对象
// path : CPDFEditPathArea 对象
}
);
pdfReaderRef.current?.addEventListener(
CPDFEvent.EDITOR_SELECTION_DESELECTED,
(editArea) => {
// event 为 CPDFEditArea 对象,可能为空
}
);