Skip to content
DemoAPI 参考文档FAQ

PDF 生成模板编辑器

开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。

查看 GitHub
React Native Guides Custom context menu

自定义上下文菜单 ​

先在上下文菜单中配置自定义菜单项,再通过 onCustomContextMenuItemTapped 处理点击事件。

onCustomContextMenuItemTapped(identifier, event) 的第一个参数是自定义菜单项的 identifier。第二个 event 参数不包含 identifier。

回调 Payload ​

上下文第二个 event 参数
截图{ image: string };不含 Data URI 前缀的 Base64。Android 为 PNG,iOS 为 JPEG(质量 0.85)。
文本选中{ text: string, rect: CPDFRectF, pageIndex: number }
页面长按{ point: { x: number, y: number }, pageIndex: number }
注释{ annotation: CPDFAnnotation }
内容编辑区域{ editArea: CPDFEditArea }
表单字段{ widget: CPDFWidget }

annotation、widget 和 editArea 会转换为 SDK 类实例;rect 和 point 保持普通 JavaScript 对象。图片编辑同样使用 editArea 字段,不存在 imageArea 事件字段。

tsx
<CPDFReaderView
  ref={pdfReaderRef}
  document={samplePDF}
  configuration={configuration}
  onCustomContextMenuItemTapped={(identifier, event) => {
    const annotation = event.annotation as CPDFAnnotation | undefined;
    if (annotation) {
      console.log(identifier, annotation.type);
    }
  }}
/>

显示截图时,请在应用中添加正确的 Data URI 前缀:Android 使用 data:image/png;base64,,iOS 使用 data:image/jpeg;base64,。

自定义工具栏操作参见自定义工具栏菜单。