Skip to content
DemoAPI 参考文档FAQ
全新发布

PDF SDK 与 AI 文档处理

在 GitHub 获取完整的私有化部署SDK 包及 AI 智能文档处理能力,一键部署,快速构建您的文档处理工作流。

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 及其子类,例如 CPDFEditTextAreaCPDFEditImageAreaCPDFEditPathAreaCPDFEvent.EDITOR_SELECTION_DESELECTED 可能返回 null

移除监听

tsx
pdfReaderRef.current?.removeEventListener(
  CPDFEvent.EDITOR_SELECTION_SELECTED,
  onEditorSelectionSelected,
);