更新记录

1.0.0(2026-07-02)

初次上传,详情请见readme文档


平台兼容性

uni-app(4.44)

Vue2 Vue3 Vue3插件版本 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
× 1.0.0 - - - - -
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - - -

其他

多语言 暗黑模式 宽屏模式
× ×

g-documentEditing

基于 uni-app + Vue 3 的移动端 PDF 文档编辑组件,支持多文件合并预览、图形批注、OCR 文本批注、水印配置等功能。

功能特性

  • 多 PDF 文件合并预览,支持滑动翻页
  • 图形批注:画笔、形状(直线/矩形/椭圆/箭头等)、橡皮擦
  • OCR 文本批注:可拖拽、双指缩放、双击编辑
  • 水印配置:明码水印与暗码水印
  • 文件目录切换,翻页自动同步激活状态
  • IndexedDB 本地文件缓存与下载进度展示
  • 搜索高亮与翻页自动搜索
  • 横竖屏自适应渲染
  • 批注数据导入/导出

依赖

  • uni-icons
  • uni-popup
  • konva(图形批注渲染)
  • pdf.js(PDF 渲染)

基本用法

<template>
  <g-documentEditing
    :files="fileList"
    :pdf-config="pdfConfig"
    :annots="annotations"
    :watermark="watermark"
    @annots="onSaveAnnots"
  />
</template>

<script setup>
import { ref } from 'vue'

const pdfConfig = ref({
  cMapUrl: '/src/static/pdfViewer/cmaps/',
  pdfPath: '/src/static/pdfViewer/pdf.mjs',
  workerSrc: '/src/static/pdfViewer/pdf.worker.mjs',
})

const fileList = ref([
  {
    fileId: '1',
    fileUrl: 'https://example.com/file1.pdf',
    fileName: '文件1.pdf',
  },
  {
    fileId: '2',
    fileUrl: 'https://example.com/file2.pdf',
    fileName: '文件2.pdf',
    readonly: true, // 只读模式
  },
])

const annotations = ref({})
const watermark = ref({
  plainContent: '内部文件请勿外传',
  color: '#e00f2d',
  fontSize: '12px',
  fontFamily: '微软雅黑',
  rotate: 45,
  width: '180px',
  height: '120px',
  transparency: '30',
})

function onSaveAnnots(annots) {
  console.log('保存批注数据', annots)
}
</script>

Props

属性 类型 默认值 说明
files Array [] 文件列表数组,每项包含 fileIdfileUrlfileName,可选 readonly(只读模式)、firstViewPage(默认展示页)
pdfConfig Object {} PDF.js 配置,包含 cMapUrlpdfPathworkerSrc
annots Object {} 批注回显数据,结构为 { [fileId]: { [pageIndex]: [...] } }
watermark Object {} 水印配置对象

files 文件项结构

字段 类型 必填 说明
fileId string 文件唯一标识
fileUrl string 文件 URL 地址
fileName string 文件显示名称
readonly boolean 是否只读,默认 false
firstViewPage boolean 是否为默认展示文件

watermark 水印配置

字段 类型 说明
plainContent string 明码水印内容
generateWatermarkData string 暗码水印内容
color string 水印颜色
fontSize string 水印字体大小
fontFamily string 水印字体
rotate number 水印旋转角度
width string 单个水印宽度
height string 单个水印高度
transparency string 水印透明度

Events

事件名 参数 说明
annots Object 保存批注时触发,返回所有文件的批注数据,结构为 { [fileId]: { [pageIndex]: [...] } }

批注数据结构

{
  "fileId1": {
    "1": [
      {
        "type": "ocr",
        "text": "批注文本",
        "color": "#333333",
        "x": 100,
        "y": 200,
        "fontSize": 16,
        "align": "left"
      }
    ],
    "2": [
      {
        "type": "tools",
        "shapeType": "zx",
        "startX": 10,
        "startY": 20,
        "endX": 100,
        "endY": 50,
        "color": "#ff0000",
        "lineWidth": 2
      }
    ]
  }
}

支持的批注类型

类型 说明
ocr OCR 文本批注
tools 图形批注(直线、矩形、椭圆、箭头等)
circleAnnotate 圈批(画笔绘制、橡皮擦)

组件结构

g-documentEditing/
├── g-documentEditing.vue        # 主组件
├── components/
│   ├── pdfPreview.vue            # PDF 预览与批注渲染
│   ├── edit-tab.vue              # 底部编辑工具栏
│   └── tools.vue                 # 工具面板
├── annotation/
│   ├── AnnotationManager.js      # Konva 批注管理器
│   ├── AnnotationSerializer.js   # 批注序列化
│   ├── BaseTool.js               # 工具基类
│   └── tools/                    # 各类绘图工具
│       ├── PenTool.js
│       ├── ShapeTool.js
│       ├── EraserTool.js
│       └── EraserClickTool.js
├── utils/
│   ├── helper.js                 # 工具函数
│   ├── drawing.js                # 绘图原语
│   ├── pdfHelper.js              # PDF 加载辅助
│   └── IndexedDB.js              # 本地缓存
└── static/                       # 图标资源

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。