Guides
内容编辑
ComPDF React Native SDK 支持内容编辑相关回调和监听事件,用于处理属性面板和可编辑内容选中状态。
可用回调和事件
| 类型 | 名称 | 触发时机 | 返回值 |
|---|---|---|---|
| 阅读器回调 | onContentEditorStyleDialogDismissed | 内容编辑属性弹窗关闭 | { type } 事件对象 |
| 监听事件 | CPDFEvent.EDITOR_SELECTION_SELECTED | 可编辑内容被选中 | CPDFEditArea |
| 监听事件 | CPDFEvent.EDITOR_SELECTION_DESELECTED | 可编辑内容取消选中 | CPDFEditArea | null |
示例
tsx
const onEditorSelectionSelected = (editArea: CPDFEditArea) => {
console.log('内容编辑对象已选中:', editArea.type);
};
const onEditorSelectionDeselected = (editArea: CPDFEditArea | null) => {
console.log('内容编辑对象已取消选中:', editArea?.type);
};
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={configuration}
onViewCreated={() => {
pdfReaderRef.current?.addEventListener(
CPDFEvent.EDITOR_SELECTION_SELECTED,
onEditorSelectionSelected,
);
pdfReaderRef.current?.addEventListener(
CPDFEvent.EDITOR_SELECTION_DESELECTED,
onEditorSelectionDeselected,
);
}}
onContentEditorStyleDialogDismissed={(event) => {
console.log('内容编辑属性弹窗已关闭:', event.type);
}}
/>CPDFEvent.EDITOR_SELECTION_SELECTED 返回 CPDFEditArea 及其子类,例如 CPDFEditTextArea、CPDFEditImageArea 和 CPDFEditPathArea。CPDFEvent.EDITOR_SELECTION_DESELECTED 可能返回 null。
移除监听
tsx
pdfReaderRef.current?.removeEventListener(
CPDFEvent.EDITOR_SELECTION_SELECTED,
onEditorSelectionSelected,
);